Take the 2-minute tour ×

It's strange & from last 5 hr it's banging my head. Don't what's going on.

Here is my jquery ajax code..

        type    : "POST",
        data    : { Message_BoardType:Message_BoardType, Operation:Operation, Class_Id:Class_Id },      
        dataType: "json",
        url     : "Mcd_MessagesBoardService.php",                                   
        cache   : false,    
        success : function(response){ 
           console.log('Response received : '+response);

Here is my JSON response string..

loadMessages{"olderBoardMessages":false,"boardMessages": [],"wallLastMessageId":0,"communicationList":[],"comments":[],"userName":"SANIDHYA  "}

My problem is even if every things working properly my ajax success callback is not working & hence my console.log is also not working.

Can any one help me to figout what's wrong i'm doing ?


share|improve this question
That isn't valid JSON... –  Jason P Aug 20 '13 at 18:13
try adding a error callback. –  palerdot Aug 20 '13 at 18:14
your code looks fine but the response JSON is not correct –  MaveRick Aug 20 '13 at 18:18
I'm using PHP's json_encode() to build JSON string. –  mi6crazyheart Aug 20 '13 at 18:25
@mi6crazyheart Then your php script isn't outputting the json properly. Are you maybe echoing some other text accidentally? –  Jason P Aug 20 '13 at 18:37

4 Answers 4

Just found, I was echoing 1 un-necessary text in my PHP script where I'm creating that JSON string.

Error Solved. Thank you all guys, for all your prompt response.

share|improve this answer

Not sure if this is your problem but when I send Json data I call JSON.stringify like this:

data: JSON.stringify({Message_BoardType:Message_BoardType, Operation:Operation, Class_Id:Class_Id})

Also if you want more detail about your problem add this:

error: function (header, status, error) {
                console.log('ajax answer post returned error ' + header + ' ' + status + ' ' + error);
share|improve this answer
OK, i think there is some error in my JSON string. But, i can't able to fig out what's that error. After adding error callback i'm getting this.. ajax answer post returned error [object Object] parsererror SyntaxError: Unexpected token l –  mi6crazyheart Aug 20 '13 at 18:44

You may want to examine the network request in the Chrome Dev Tools to determine the response is successful. Also, when I do a $.ajax() POST, I do it like this:

$.ajax("Mcd_MessagesBoardService.php", {
    type: "POST",
    contentType: "application/json",
    data    : { Message_BoardType:Message_BoardType, Operation:Operation, Class_Id:Class_Id },
    console.log('Response received : '+response);

Although the data attribute depends on what your php expects.

share|improve this answer

The data you are sending doesn't seem to be a valid json first of all, check validity here: http://jsonlint.com/

Also, if you are doing this on localhost, the browsers might protect against it. Open the javascript console (ctrl+shift+j on Chrome, ctrl+shift+k on Firefox) and see if there is something about Cross-origin access. You need to surround your return json with callback(json) and pass a callback=? request from the function.

share|improve this answer
Nops, i'm not making any cross domain calls. All files are in localhost only. –  mi6crazyheart Aug 20 '13 at 18:26

Your Answer


