2014-11-05 46 views
1

我已經包含了所需的文件:不能發佈使用AJAX英特爾XDK

,但似乎無法讓我的AJAX後提交。似乎事件在帖子前停止。我正在開發一個使用IntelXDK的應用程序,並沒有很多關於如何使AJAX後期工作的細節...不知道我錯過了什麼。有任何想法嗎?

我的ajax:

$.ajax({ 
    url : 'http://xx.xxx.xx.x/check_access.php', 
    type: 'POST', 
    data : {'thisusername':thisusername, 'thispassword':thispassword}, 
    dataType: 'Text', 
    success: function(data, textStatus, jqXHR) 
    { 

     if(data==1){ 
        localStorage.setItem("username2", thisusername); 
        location.assign("./community-home.html"); 
     } else { 
       function funcError1() { 
        var iframe5 = document.createElement("IFRAME"); 
        iframe5.setAttribute("src", 'data:text/plain,'); 
        document.documentElement.appendChild(iframe5); 
        window.frames[0].window.alert('Username or Password does not exist.'); 
        iframe5.parentNode.removeChild(iframe5); 
       } 
       funcError1(); 
     } 
    }, 
    error: function(){ 
      //$("#user-result").html("Username available!"); 
      function funcError() { 
       var iframe4 = document.createElement("IFRAME"); 
       iframe4.setAttribute("src", 'data:text/plain,'); 
       document.documentElement.appendChild(iframe4); 
       window.frames[0].window.alert('Something went wrong. Close the application and try again'); 
       iframe4.parentNode.removeChild(iframe4); 
      } 
      funcError(); 

      console.log('There was an error'); 
    } 

}); 
return false; 
} 

回答

1

爲了讓你做出Ajax請求英特爾XDK或應用內的國外網站或服務的XDK建,我建議你添加xhr.js HEAD元素中的腳本。

例如,

<!DOCTYPE html><!--HTML5 doctype--> 
<html> 
<head> 
    <title>Your New Application</title> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" /> 
    <style type="text/css"> 
     /* Prevent copy paste for all elements except text fields */ 
     * { -webkit-user-select:none; -webkit-tap-highlight-color:rgba(255, 255, 255, 0); } 
     input, textarea { -webkit-user-select:text; } 
     body { background-color:white; color:black } 
    </style> 
    <script src='intelxdk.js'></script> 
    <script src='cordova.js'></script> 
    <script src='xhr.js'></script> 
    <script type="text/javascript"> 
     var onDeviceReady=function(){        // called when Cordova is ready 
      if(window.Cordova && navigator.splashscreen) {  // Cordova API detected 
       navigator.splashscreen.hide() ;     // hide splash screen 
      } 
     } ; 
     document.addEventListener("deviceready", onDeviceReady, false) ; 
    </script> 
</head> 
<body> 
<!-- content goes here--> 
    <h2>Hello World</h2> 
</body> 
</html> 

有關英特爾XDK內使Ajax請求的更多信息,請訪問https://software.intel.com/en-us/html5/articles/how-to-access-JSON-data-in-HTML5-apps