I am making a call to a server which returns a JSON encoded object. This object has to be present before I can continue processing, therefore I am setting async:false in the request which looks like this:
var response = null;
$.ajax({
type: 'POST',
url: 'ajax/test',
dataType: 'json',
async: false,
data : ({data : requests}),
success: function(data) {
response = data;
}
});
If async: true is set, I get the following object returned:
openGeolocationDialog Object { show=0, data=""}
If async: true is set, I get the same object returned, but with an additional 'jQuery...' property:
openGeolocationDialog Object { show=0, jQuery16209069375968417921={...}, data=""}
Why is this being returned and how can I suppress it?
Synchronous requests are bad from a user point of view: They block the browser.
You should just continue processing in the success callback:
$.post('ajax/test', {request: data}, function(response) {
// continue here
});
Take a look at Deferred, too.
BTW you don't need dataType: 'json'
if the server returns the proper content-type (i.e. application/json
).