1

我在 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/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"
        }
    ]
}
4

1 回答 1

0

toString是大多数对象的方法。

你的线result.response.toString.length应该是result.response.toString().length

于 2012-11-28T13:09:57.597 回答