这个错误的原因是什么?我该如何解决? 误差与谷歌浏览:在Ajax调用中不同的浏览器出现不同的错误
An error has occured: [object Object] parsererror SyntaxError: Unexpected token ILLEGAL
错误歌剧:
An error has occured: [object Object] parsererror SyntaxError: JSON.parse: Unable to parse value:
错误与IE9:
An error has occured: [object Object] parsererror SyntaxError: Invalid character
和...
JS代码:
$('#hotel').keypress(function() {
var dataObj = $(this).closest('form').serializeArray();
$.ajax({
url: 'http://localhost/mehdi/admin/tour/search_hotel',
data: dataObj,
dataType: 'json',
success: function (data) {
$("#suggestion_tab").html('');
$.each(data.suggestions, function (a, b) {
$("#suggestion_tab").append('<li>' + data.b + '</li>');
});
// Display the results
///alert(data);
},
"error": function (x, y, z) {
// callback to run if an error occurs
alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
}
});
});
PHP:(是CI_Controller)
function search_hotel(){
$searchterm = $this->input->post('search_hotel');
$result = $this->model_tour->search_hotel($searchterm);
while($row = mysql_fetch_assoc($result))
{
$output[] = $row;
}
echo json_encode(array('suggestions' => $output));
}
CI_Model
function search_hotel($searchterm)
{
return mysql_query("select * from hotel_submits where name LIKE '".$searchterm."'");
}
实际回应是什么? – SLaks
这听起来像你的JSON响应是无效的,它看起来如何? – enricog
在firebug中检查你得到了什么json,并用'www.jsonlint.com'验证json – Rafay