1

I'm doing an AJAX call like so:

function getEvents(info){
  $.ajax({
    url: 'get_all_events.php',
    data: {year: info['year'],month: info['month']},          
    type: 'POST',
    dataType: 'json',
    success: function (result) {
        alert(JSON.stringify(result));
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        console.log(XMLHttpRequest.statusText);
        console.log(textStatus);
        console.log(errorThrown);
    }
});
}

Which works on the initialization of the calendar app I'm developing. I create an object 'info' and assign it month/date etc... then when the user presses 'Previous' or 'Next' it reassigns certain variables of the 'info' object and calls getEvents again. I tried re-writing my query, rewriting my AJAX call, adding contentType... nothing seems to work.

2
  • Did you check, while re-assigning the values in info object, what values do it contain, and what is the value of result? Check these values using console. Commented Feb 10, 2013 at 16:04
  • Yes, right before I send them out to the AJAX call, I verified that the JavaScript object 'info' contains the right values (which it does). Commented Feb 11, 2013 at 16:20

1 Answer 1

1

see if there are any errors in the console. Also make sure, your get_all_events.php returns the valid JSON string. When you specify dataType:'json' jQuery will automatically parse the returned data. If the data that is returned is not a valid JSON this error is thrown.

How to check?

Do one thing. Remove dataType:'json', attribute from your $.ajax() call... console.log(result) in your success handler... Copy the response text from console and paste it inside some online JSON validator (jsonlint.com) if there is and error, update get_all_events.php on server side to echo the valid JSON

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic idea, I will try this tonight. If this isn't the case, I will setup my debug mode and release the link in an update of my question. Thank you for your suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.