Php 使用WinJS.xhr()检索JSON:
在winjs.xhr中检索聊天信息时遇到问题:Php 使用WinJS.xhr()检索JSON:,php,javascript,json,windows-runtime,Php,Javascript,Json,Windows Runtime,在winjs.xhr中检索聊天信息时遇到问题: function getMessage() { var time = MESSAGE_RETURNED.unixtime; if (time == 0) { time= window.parent.SESSION.unixtime; } WinJS.xhr({ url: "http://www.example.com/scripts
function getMessage() {
var time = MESSAGE_RETURNED.unixtime;
if (time == 0) {
time= window.parent.SESSION.unixtime;
}
WinJS.xhr({
url: "http://www.example.com/scripts/default.php?"
+ "action="+ACTIONS.GET_MESSAGE
+ "&username=" + window.parent.SESSION.username
+ "&session_id=" + window.parent.SESSION.session_id
+ "&unixtime=" + time
}).done(
function fulfilled(result) {
console.log("action=" + ACTIONS.GET_MESSAGE
+ "&username=" + window.parent.SESSION.username
+ "&session_id=" + window.parent.SESSION.session_id
+ "&unixtime=" + time);//CHECK INPUTS , ALL GREEN
if (result.status === 200) {
if (result.response.toString.length === 0) {
return false;
}//ALWAYS TRUE;
else {
console.log(JSON.parse(result.response));
}
} else {
document.getElementById("messagelogarea").value += result.status + "\r\n";
}
});
}
我正在尝试从php检索JSON。但是,当使用WinJS.xhr时,我返回的响应总是空的。如果将直接链接放在我的浏览器中,我将得到如下结果:
包含3条聊天信息的数组
{
"message": [
{
"_id": "428",
"from_TBonlineusers_id": "00477",
"fromTBonlineusers_username": "GUEST_477",
"fromTBonlineusers_type": "GUEST",
"messagetype": "PUBLIC",
"message": "wat?xxwiii",
"chatmessagetime": "2012-11-16 15:36:06",
"unixtime": "1353098166"
},
{
"_id": "429",
"from_TBonlineusers_id": "00477",
"fromTBonlineusers_username": "GUEST_477",
"fromTBonlineusers_type": "GUEST",
"messagetype": "PUBLIC",
"message": "wat?xxwiii",
"chatmessagetime": "2012-11-16 15:42:42",
"unixtime": "1353098562"
},
{
"_id": "430",
"from_TBonlineusers_id": "00477",
"fromTBonlineusers_username": "GUEST_477",
"fromTBonlineusers_type": "GUEST",
"messagetype": "PUBLIC",
"message": "wat?xxwiiir",
"chatmessagetime": "2012-11-16 15:42:48",
"unixtime": "1353098568"
}
]
}
toString是大多数对象的一种方法
您的行result.response.toString.length应该是result.response.toString.length首先,您是否已授予应用程序在appxmanifest中访问internet的权限?是否从同一域/子域调用服务器端页面?[回答验证或使我的解决方案无效。]是。我只使用了一个域。当您查看从服务器返回的响应[fiddler、firebug等]时,它看起来正确吗?您还应该对querystring值进行编码。您有result.response.toString.length。是否应该是result.response.toString.length?