我有一個調用php腳本的jquery.ajax例程。 php腳本在Google搜索API上進行查找並將json返回給調用的ajax腳本。jQuery.ajax返回錯誤:出現錯誤消息的意外標記:parseerror?
該腳本工作正常上安裝的99%,但是,在少數,當我打電話:
error: function(jqXHR, textStatus, errorThrown){
alert('HTTP Error: '+errorThrown+' | Error Message: '+textStatus);
}
它返回:
HTTP Error: SyntaxError: Unexpected token < | Error Message: parsererror
如何使用JavaScript控制檯我解決此或Chrome開發者工具?代碼存根低於...
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的對象錯誤寫着:
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"
聽起來像你有不正常的json回來。 ''會暗示可能是一個纏繞json的html標籤? –
哪些區域設置?你爲json返回的URL是什麼?也許你會得到XML呢?請提供更多信息。 – hakre
@hakre:謝謝你檢查了這一點。我剛剛更新了這個問題。 – RegEdit