JQueryMobile - AJAX - JSON 解析

发布于 2024-10-06 13:43:39 字数 805 浏览 0 评论 0原文

任何人都可以帮助我。我使用以下代码在 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 输出
[ { "type":"企业简介", "title":"湖景餐厅", "user":"canwest", "日期":"1280144992", “节点”:{ "nid":"67916", "type":"business_profiles", “语言”:””, “uid”:“1”, “状态”:“1”, “创建”:“1278994293” } } ]

Any one help me . I am using the following code for calling web service in jquery mobile. But I am getting the error " Undefined". Please point out me where I done the mistake. THanks in advance.

Coding :

$.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 Output
[
{
"type":"Business Profiles",
"title":"Lakeview Restaurant",
"user":"canwest",
"date":"1280144992",
"node":{
"nid":"67916",
"type":"business_profiles",
"language":"",
"uid":"1",
"status":"1",
"created":"1278994293"
}
}
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别低头,皇冠会掉 2024-10-13 13:43:39

您将返回一个数组,而不是一个基础对象 - 即使如此,我也看不到 message 属性,所以它应该是:

alert(msg[0].title);

或者,循环遍历所有这些 - 例如:

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

You're getting an array back, not a base object - and even then there's no message property that I can see, so it should be:

alert(msg[0].title);

Or, loop through them all - for example:

$.each(msg, function(i, profile) {
  alert(profile.type);
  alert(profile.node.nid);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文