我試圖調試以下jQuery.ajax()調用:jQuery.ajax()調用返回JSON.parse意外字符錯誤
var rollnum = $('#rollNum').val()
$.ajax({
url: sURL + "myController/myMethod",
type: "POST",
data: {rollnum: rollnum},
dataType: 'json',
success: function(json){alert(json)},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);}
});
這裏是方法:
function myMethod(){
$query = $this->db->query("SELECT tblontario.Address, tblontario.Municipality FROM tblontario WHERE RollNum = 211010002528200");
$json_address = array();
$json_municipality = array();
foreach ($query->result_array() as $row){
$json_address[] = $row['Address'];
$json_municipality[] = $row['Municipality'];
}
$json['address'] = $json_address;
$json['municipality'] = $json_municipality;
echo json_encode($json);
exit;
}
目前發生的情況是我收到了一個錯誤。錯誤是由這些細節:
xhr.status: 200; and
thrownError: SyntaxError: JSON.parse: unexpected character
當我看XHR響應選項卡中螢火它表明:
Reload the page to get source for: http://www.mysite.ca/myController/myMethod
東西似乎是正常工作,因爲我們得到的200 xhr.status ,但我似乎無法從此調用中檢索返回的json數據。任何人都可以給我一個什麼問題的建議?謝謝。
實際迴應是...? – 2012-07-19 05:23:03