如何使用JQuery讀取像這樣的Json響應:{"result":{"_id":{"Timestamp":23232323, "Machine:4235245252"}, "Agency":"Crooars", "City":"New York", "State": "New Jersey"}}
我想閱讀Agency
,City
和State
,其他字段不相關。 我曾與一些嘗試這樣的:在JQuery中讀取Json字段
$.ajax({
type: 'post',
url: urlPostGraduate,
data: $("#formPostGrad").serialize(),
success: function (result) {
alert(result.Agency) // returns undefined
alert(result._id.Agency) // it doesn't even show the alert
alert(result["_id"].Agency) //neither
}
嘗試alert(result.result.Agency); – shakib
不使用'alert()',使用'console.log()'。然後使用'console.log(result)'。這是你所期待的嗎? –