2014-11-05 62 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