Ho una routine jquery.ajax che chiama uno script php. Lo script php esegue una ricerca nell'API di ricerca di Google e restituisce json allo script ajax chiamante.jQuery.ajax restituisce errore: token imprevisto con messaggio di errore: parseerror?
Lo script funziona bene su 99% delle installazioni, tuttavia, su alcuni, quando chiamo:
error: function(jqXHR, textStatus, errorThrown){
alert('HTTP Error: '+errorThrown+' | Error Message: '+textStatus);
}
Restituisce:
HTTP Error: SyntaxError: Unexpected token < | Error Message: parsererror
Come posso risolvere questo utilizzando JavaScript console o strumenti di sviluppo di Chrome? Codice stub è inferiore ...
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: Errore oggetto di console.log legge:
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"
Sembra che tu abbia malformato JSON tornare. Il simbolo <
Quale locale? Qual è l'URL che licenzi per il ritorno di JSON? Forse ottieni XML invece? Si prega di fornire maggiori informazioni. – hakre
@hakre: grazie per averlo verificato. Ho appena aggiornato la domanda. – RegEdit