1 decade ago by clliu
Hi Everyone,
I'm currently using ajax call to get contents for my game. It works fine in XDK Emulator but not working on iPhone on both test local or test everywhere. I included xhr.js by <script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/xhr.js"></script>
I couldn't work out what's wrong please help.
ajax code:
After some debugging and trace I found the difference between emulator and iPhone is on iPhone the logic stopped at line 76 in xhr.js (in XMLHttpRequest.Extension.handleResponseData)
I'm currently using ajax call to get contents for my game. It works fine in XDK Emulator but not working on iPhone on both test local or test everywhere. I included xhr.js by <script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/xhr.js"></script>
I couldn't work out what's wrong please help.
ajax code:
GetUserQuestions: function (userId, questionNo, f){ var that = this; var dataValue = JSON.stringify({ userId: userId, questionCount: questionNo }); $("#startPauseDiv").html('in GetUserQuestions, data:' + dataValue); $.ajax({ type: "POST", url: "http://dieutan.com/BabyQuestion.asmx/GetUserQuestions", data: dataValue, contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $("#startPauseDiv").html('got message back from web server: ' + msg); if (msg.d) { that.Questions = msg.d; that.currQIndex = 0; $("#startPauseDiv").html("got answer from web service. " + that.Questions.length); } else { that.EmptyQuestion(); $("#startPauseDiv").html(that.ErrMsgLoading); } if (typeof f == "function") f(that.Questions, that.currQIndex); }, fail: function(){ $("#startPauseDiv").html(that.ErrMsgLoading); that.EmptyQuestion(); } }); },
After some debugging and trace I found the difference between emulator and iPhone is on iPhone the logic stopped at line 76 in xhr.js (in XMLHttpRequest.Extension.handleResponseData)
// in iPhone XMLObj.onreadystatechange is also function but execute this function will not lead to success: function (msg) , while in emulator it will. if (typeof XMLObj.onreadystatechange == 'function') XMLObj.onreadystatechange(); if (typeof XMLObj.onloadstart == 'function') XMLObj.onloadstart(); if (typeof XMLObj.onload == 'function') XMLObj.onload(); } }