Uncomprehensible jQuery $.ajax() behavior when data contains consecutive question marks

jQuery uses ?? as a placeholder for the callback function when using jsonp. When it parses an Ajax request, and it finds the double questionmark (or more questionmarks), it automatically assumes that you are trying to use jsonp. When you set the content-type manually, it will ignore the questionmarks.

So, avoid the problem by using contentType:

$.ajax(
    url: "your-url.php",
    dataType: "json",                 // what you expect the server to return
    contentType: "application/json",  // what you are sending
    ...
);

For reference:

jQuery Bugtracker: $.AJAX CHANGED THE POST CONTENT IF INCLUDE “??” (2 QUESTION MARK)

Hopes it saves someone else from hours of debugging…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)