从 PHP (json_encode) 获取一些数据,现在需要在 javascript 中访问它?
我目前正在使用 Phonegap 和 XUI 来创建 Web 应用程序。
我正在通过 XUI 使用 http 请求从外部域检索一些数据。
这工作正常,我正确接收到 JSON 数据,请参阅下面的数据格式:
({"first":"John","last":"Smith","HighScore":"75"})
所以现在我希望能够使用 javascript 访问数据的各个资产。
x$('#test').xhr(URL,function() {
loggedin = this.responseText; // This is the data that has been received from the PHP file
if(loggedin != '1') // If not 1 then will let them in
{
alert(loggedin); // Alerts with the data recieved
}
else // Login incorrect
{alert('Sorry you login details were incorrect please try again.');}
});
我知道这可能很简单,但我似乎无法弄清楚,所以任何帮助将不胜感激。
谢谢,
凯恩
I am currently using Phonegap and XUI to create web app.
I am retrieving some data from an external domain using a http request via XUI.
This is working correctly and I receive the JSON data back correctly, see the data format below:
({"first":"John","last":"Smith","HighScore":"75"})
So now I want to be able to access the individual assets of the data using javascript.
x$('#test').xhr(URL,function() {
loggedin = this.responseText; // This is the data that has been received from the PHP file
if(loggedin != '1') // If not 1 then will let them in
{
alert(loggedin); // Alerts with the data recieved
}
else // Login incorrect
{alert('Sorry you login details were incorrect please try again.');}
});
I know its probably simple to do but I just can't seem to figure it out so any help would be much appreciated.
Thanks,
Kane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 对象访问器语法为
object.key
,因此如果this.responseText
为{"first":"John","last":"Smith"," HighScore":"75"}
然后您将显示Smith
和this.responseText.last
警报的示例用法如下:
JSON object accessor syntax is
object.key
, so ifthis.responseText
is{"first":"John","last":"Smith","HighScore":"75"}
then you'd displaySmith
withthis.responseText.last
An example usage for your alert could be: