gpt4 book ai didi

javascript - JQueryMobile - AJAX - JSON 解析

转载 作者:行者123 更新时间:2023-11-30 18:49:32 25 4
gpt4 key购买 nike

谁帮帮我。我正在使用以下代码在 jquery mobile 中调用 Web 服务。但我收到错误“未定义”。请指出我哪里做错了。提前致谢。

编码:

$.ajax({
type: 'POST',
url: "http://jquery.sample.com/nodes.json",
data: ({search_keys :theName}),
dataType: 'json',
timeout: 5000,
success: function(msg)
{
console.log(msg); //here, I can see the result in browser.
alert(msg.message); //Undefined Error
},
error: function(xhr, status, errorThrown)
{
alert(status + errorThrown);
}
});

JSON 输出
[ { “类型”:“业务概况”, "title":"湖景餐厅", “用户”:“加西”, “日期”:“1280144992”, “节点”:{ “nid”:“67916”, “类型”:“business_profiles”, “语言”:””, “uid”:“1”, “状态”:“1”, “创建”:“1278994293” } }]

最佳答案

你得到的是一个数组,而不是一个基础对象——即使这样我也看不到 message 属性,所以它应该是:

alert(msg[0].title);

或者,遍历它们 - 例如:

$.each(msg, function(i, profile) {
alert(profile.type);
alert(profile.node.nid);
});

关于javascript - JQueryMobile - AJAX - JSON 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4385807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com