我想閱讀與jQuery的響應,我不知道它如何與響應一起工作。如何閱讀與jQuery的JSON響應
見與JS後+響應的小例子代碼在這裏:
$.ajax({
url: "http://localhost/ajaxpost/ajax.php",
type: "post",
data: "action=check&uid=1",
dataType: "json",
success: function(data){
$("#result").html('submitted successfully');
response = JSON.parse(data);
status = response.status;
alert(status);
},
error:function(){
$("#result").html('there is error while submit');
}
});
的迴應是:
{"first":"John","last":"Heyden","uid":"1","token":"10","value":"100000","friends":"23","country":"australia","status":"online"}
現在我想這是alert online
有人能告訴我我在這裏錯過了什麼?
當我刪除數據類型: 「JSON」,這工作正常
success: function(data){
$("#result").html('submitted successfully');
var r = jQuery.parseJSON(data);
alert(r.status);
你確定你需要解析'data'嗎?我認爲這應該是一個JavaScript對象已經 – musefan