Maybe i get minuses for this question, but i have problems with success and i really don’t see differences between example of using success from jQuery documentation:
$.ajax({
url: "test.html",
context: document.body,
success: function(){
$(this).addClass("done");
}
});
and my code:
$('#my_form').live('submit', function(){
var data = $("#form_for_item").serialize();
var url = '/something/add_something/' + $('#form_for_item').attr('name') + '/';
$.ajax({
type: 'POST',
url: url,
data: data,
success: function(){
alert('problem!')
},
dataType: 'json'
});
return false;
});
For more i can say that data is sent via post and save in my database, and for more than more i can say that when i have success: alert('problem!') there is no problem.
What is wrong with my success?
Perhaps your server isn’t returning JSON data. Usually you can leave it up to
$.ajaxto figure out what sort of data the server is responding with by checking the Content-Type header and possibly other means. Try dropping thedataType.Also, using:
Gets you your
alertbecause that will be executed while the$.ajaxcall’s options object is being built and there won’t be a success callback at all.