jQuery AJAX post callback doesn't seems to work

I did this lots of times:

var url = '/offers/1/voting';
var params = { 'direction': 'up' };
$.post(url, params, function() {
  alert('callback');
}); // post

(I'm hardcoding the values for this example, but nothing)

So, through firebug I receive the desired JSON response (200 status), but the callback doesn't execute. It's pretty much the only javascript I'm using. Tried with jquery 1.6.4 and 1.7.1 and it's the same thing with both. I don't know what I'm missing.

Help me, Stack Overflow. You're my only hope.

Answers


If you use $.ajax instead of $.post ($.post is really an overwrite of $.ajax with fewer parameters), you can add a handler for error and see if it fires:

jQuery.ajax({
        type: "POST",
        async: true,
        url: '/offers/1/voting',
        data:  { 'direction': 'up' },
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (msg) 
                { alert('success') },
        error: function (err)
        { alert(err.responseText)}
    });

Need Your Help

Simply / condense this code?

jquery each

I often find myself writing two blocks of code — one for the init and the same for on change, like below. Suggestions for a more condensed / elegant approach?

Getting at C binary data from OCaml

c ocaml binary-data ffi

(Ignoring endianness for the sake of argument - this is just a test case/proof of concept - and I would never use strcpy in real code either!)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.