Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自Intex XDK的Ajax连接失败_Php_Jquery_Ajax_Apache_Intel Xdk - Fatal编程技术网

Php 来自Intex XDK的Ajax连接失败

Php 来自Intex XDK的Ajax连接失败,php,jquery,ajax,apache,intel-xdk,Php,Jquery,Ajax,Apache,Intel Xdk,我在使用Ajax从手机连接到php页面时遇到问题。我已经尽可能简化了交易。服务器端代码为: <?php echo(json_encode('success')); ?> $.ajax({ ‘url’: "http://www.skynet.ie/~lobo/test.php", ‘success’: function(results){ alert(results);

我在使用Ajax从手机连接到php页面时遇到问题。我已经尽可能简化了交易。服务器端代码为:

<?php
    echo(json_encode('success'));
?>
$.ajax({
           ‘url’: "http://www.skynet.ie/~lobo/test.php",
           ‘success’: function(results){
                   alert(results);                      
           },
           ‘error': function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(JSON.stringify(XMLHttpRequest));
}
});
从“英特尔XDK仿真器”进行测试时,我得到了成功的响应。当我从手机IOS启动应用程序时,我得到:

readyState:0,responseText:,状态:0,状态文本:“错误”

从错误函数。我试着添加

header('content-type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");
转到php页面没有用。我已将$.support.cors设置为true;在当地。我尝试过使用$.getJSON和几乎所有与之相关的ajax选项。我从手机上成功地获得了连接到的响应,并且我可以在模拟器中从我自己的站点获得响应。我真的不知道当我尝试从手机连接到服务器时会出现什么问题。我想任何见解都将不胜感激


Stephen

您遇到了CORS问题。请尝试以下操作:

为了使您能够向Intel XDK内的外国网站或XDK构建的应用程序发出ajax请求,我建议您在HEAD元素中添加xhr.js脚本

比如说,

<!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='xhr.js'></script>
    <script type="text/javascript">
        /* Intel native bridge is available */
        var onDeviceReady=function(){
        //hide splash screen
        intel.xdk.device.hideSplashScreen();
        };
        document.addEventListener("intel.xdk.device.ready",onDeviceReady,false);
    </script>
</head>
<body>
<!-- content goes here-->
    <h2>Hello World</h2>
</body>
</html>

有关在“英特尔XDK”中发出ajax请求的更多信息,请转到我发现的相同问题。这似乎是Intel XDK软件中的一个bug,所有新项目都是通过模板创建的,而忽略了ajax调用。我刚刚将我的project www文件夹导入到一个新项目中,ajax调用现在正在工作。我知道这对你来说可能太晚了,但希望它能帮助其他人。

你如何构建ios?或者你正在使用应用程序预览?它是通过应用程序预览运行的。我意识到这看起来确实像是CORS问题,但我尝试添加xhr.js,得到了完全相同的结果。