在我的螢火我看到與服務器響應:爲什麼parseJSON在來自服務器的以下響應中失敗?
{"status":"Results Found","errorcode":"0","result":[{"name":"test","id":"1"},{"name":"some","id":"2"}]}
When I do the following I get a "o is null" error.
$.ajax({
type: "get",
url: "http://someurl",
data: $("#eventsearch").serialize(),
dataType: 'json',
success: function(msg){
var o = $.parseJSON(msg); //o is NULL error
}
然而,當我做的parseURL在同一個字符串,但不能作爲服務器響應一切都很好。這裏發生了什麼?
var t = '{"status":"Results Found","errorcode":"0","result":[{"name":"test","id":"1"},{"name":"some","id":"2"}]}';
var o = $.parseJSON(t); //everything is good here