I have a jquery.ajax routine that calls a php script. The php script does a lookup on the Google search API and returns json to the calling ajax script.
The script works fine on 99% of installs, however, on a few, when I call:
error: function(jqXHR, textStatus, errorThrown){
alert('HTTP Error: '+errorThrown+' | Error Message: '+textStatus);
}
It returns:
HTTP Error: SyntaxError: Unexpected token < | Error Message: parsererror
How can I troubleshoot this using javascript console or chrome developer tools? Code stub is below...
var result='';
jQuery.ajax
({
contentType: "application/json; charset=utf-8",
dataType: "json",
url: <?php echo '"' .plugins_url('/script.php', __FILE__); ?>?Query="+ jQuery('#search_keyword').val(),
success: function(data)
{
//do something with results
},
error: function(jqXHR, textStatus, errorThrown){
console.log(arguments);
alert('HTTP Error: '+errorThrown+' | Error Message: '+textStatus);
return;
}
});
UPDATE: Console.log's OBJECT error reads:
responseText: "<br />↵<b>Warning</b>: array_map() [<a href='function.array-map'>function.array-map</a>]: Argument #2 should be an array in <b>/filepath/wp-content/plugins/test/test.php</b> on line <b>75</b><br />↵<br />↵<b>Warning</b>: Invalid argument supplied for foreach() in <b>/filepath/wp-content/plugins/test/test.php</b> on line <b>90</b><br />↵No Records Returned. Search may be down. Wait a few minutes"
You probably have HTML returning where it was not supposed to for the JSON.
Try console.log(arguments);
before the alert to see what is returned
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With