You can try the following:
var data=$.ajax({ type: "POST", url: 'ajax.php', data: { data:str }, async: false, dataType: 'json' }); var msg= data.responseText; msg=jQuery.parseJSON(msg);
I usually send either an array or an error message on my php page
if(msg=='error') { } else
This works with jquery 1.6-> 1.8
EDIT: Since jquery 1.8 async is deprecated. I would recommend this format:
$.ajax({ type: "POST", url: 'ajax.php', data: { data:str }, dataType: 'json', ).done(function(data) {
http://api.jquery.com/jquery.ajax/
Indra source share