使用Visual Studio在Cordova中进行HTTP POST失败 - php

我一直试图获得一个简单的HTTP POST,以将基于cordova的应用程序连接到服务器(基于php)。

我已经为测试目的编写了一个简单的php文件。

邮递区号:

<?php
    if (isset($_POST["TEST"])){
        echo "TEST WORKS!!";
    }
?>

现在我的cordova应用程序中的jQuery代码>

// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkID=397704
// To debug code on page load in Ripple or on Android devices/emulators: launch your app, set breakpoints, 
// and then run "window.location.reload()" in the JavaScript Console.
(function () {
    "use strict";

    document.addEventListener('deviceready', onDeviceReady.bind(this), false);

    function onDeviceReady() {
        // Handle the Cordova pause and resume events
        document.addEventListener('pause', onPause.bind(this), false);
        document.addEventListener('resume', onResume.bind(this), false);

        // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
        //My Code
        $('#btnSend').on('click', function () {

            $.post('http://mobtest.bugs3.com/test.php',
                { TEST: 'TEST' },
                function (result) {
                    alert(result);
                    $('#txtlbl').text(result);
                },
                function (error) {
                    alert(error);
                    $('#txtlbl').text(error);
                }
            );

        });
    };

    function onPause() {
        // TODO: This application has been suspended. Save application state here.
    };

    function onResume() {
        // TODO: This application has been reactivated. Restore application state here.
    };
})();

这是基于Visual Studio提供的用于Apache / Cordova构建的模板构建的。

当我单击按钮时,我在控制台中看到以下消息:

http://localhost:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//mobtest.bugs3.com/test.php Failed to load resource: net::ERR_CONNECTION_REFUSED

哪里http://mobtest.bugs3.com/test.php

是php文件的网址。

编辑

经过一番研究,我发现是CROSS DOMAIN PROXY引起了问题。

现在最新的错误消息是:

XMLHttpRequest cannot load http://mobtest.bugs3.com/test.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4414' is therefore not allowed access.

在此问题上寻求帮助。

参考方案

找到了答案here。将跨域代理设置更改为“远程”或“禁用”。默认情况下,它设置为“本地”,不允许跨域资源访问。

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

PHP Laravel从另一个驱动器读取文件 - php

我目前正在学习Laravel。我想知道是否有一种方法可以在Laravel中使用Storage::从另一个硬盘访问文件(使用Windows)。例如,我在驱动器C:上安装了带有Laravel的Xampp,但是我想访问网站目录之外的E:上的文件。我试过使用Storage::files('E:')和File::files('E:…

php:拆分字符串,直到第一次出现数字 - php

我有像cream 100G sup 5mg Children 我想在第一次出现数字之前将其拆分。所以结果应该是array( array('cream','100G'), array('sup','5mg Children') ); 可以告诉我如何为此创建图案吗?我试过了list(…