【问题标题】:Can't Post using AJAX in Intel XDK无法在英特尔 XDK 中使用 AJAX 发布
【发布时间】:2014-11-05 16:56:43
【问题描述】:

我已经包含了所需的文件:

但似乎无法让我的 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;
}

【问题讨论】:

    标签: jquery ajax intel-xdk


    【解决方案1】:

    为了让您向英特尔 XDK 中的外部网站或服务或 XDK 构建的应用程序发出 ajax 请求,我建议您添加 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>
    

    有关在 Intel XDK 中发出 ajax 请求的更多信息,请转至https://software.intel.com/en-us/html5/articles/how-to-access-JSON-data-in-HTML5-apps

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多