jQuery ajax callback function not working
I am using Symfony PHP Framework to create web application, and using symfony Forms to create the HTML forms. I am trying to load the data in Select element using Ajax, for that i am using jQuery's Ajax functions. It is working fine as it sends and gets the response correctly(status as 200), but not calling the Callback function in some browsers such as IE,Chrome and Safari.It works fine in Firefox and Opera. the Code that is not working,
$.ajax({
type: 'POST',
url: 'form/ajax',
async: true,
cache: false,
dataType : 'json',
data: 'id='+ids,
开发者_开发问答 success: function(jsonData){
alert("ok go");
}
});
the alert "OK Go" is not called in Chrome,IE and Safari But
$.ajax({
type: 'POST',
url: 'form/ajax',
async: true,
cache: false,
dataType : 'json',
data: 'id='+ids,
success: alert("ok go");
});
this works, but as per the project i want the JSON data to load in my Select element. is there any thing wrong in the return JSON format or the bug in the jQuery Ajax functions, please help.
You were almost there. replace 'id=' + ids
with 'id:'+ids
UPDATE: I've written a JQuery plugin which makes ajax calls and json serializing very easier. you can download it at: http://www.4shared.com/file/8hHJll-R/Pagemethod-2.html
First of all thanks @Kamyar and @Brad Christie, to help me solve the problem. while inspecting as Kamyar said to change the format of id to JSON format, i checked the return format for JSON, and found that it was causing the problem, as it was not a valid JSON format. The return JSON format was causing the Problem! return JSON with error,
{"ugdegree":[{"id":31,"specialization":"Dentistry"},{"id":32,"specialization":"Other"},]}
there was an extra comma at the end(causing the problem) Now it has been fixed! so if anyone having the same problem, please check for the JSON format! if that might be the case.
精彩评论