1
我已經有在winjs.xhr檢索chatmessages麻煩
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 retrive 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"
}
]
}
首先第一件事情,你有沒有授予您appxmanifest與互聯網的應用程序的訪問? – Sampson
是的,能夠發送消息。 – wtsang02
你是從同一個域/子域調用服務器端頁面嗎? [回答要麼是驗證我的解決方案,要麼是無效的。] – epascarello