简体   繁体   English

AJAX发布请求可在浏览器中运行,而不是在Phonegap App上运行

[英]AJAX post request working in browser, not on Phonegap App

A simple AJAX request is failing when I test it using the Phonegap App on iOS10. 当我在iOS10上使用Phonegap应用程序对其进行测试时,一个简单的AJAX请求失败。

Code is as follows (works perfectly in browser): 代码如下(在浏览器中完美运行):

if($.trim(firstname).length > 0 & $.trim(email).length > 0 & $.trim(password).length > 0) {

            console.log("input checked");

            $.support.cors = true;
            $.ajax({
                type: "POST",
                url: "http://my-server.com/signup.php",
                data: dataString,
                crossDomain: true,
                cache: false,

                beforeSend: function(data) {
                    console.log("connecting to server");
                },

                //display success/fail message - put something in data on server
                success: function(data, textString, xhr) {
                    if(data == "success") {
                        localStorage.login = "true";
                        localStorage.email = email;
                        mainView.router.loadPage("swipe.html");
                    } else if(data == 'exist') {
                        myApp.alert("Account already exists", "Login Failed");
                    }
                },

                error: function(xhr, ajaxOptions, errorThrown) {
                    console.log("error msg: ");
                    console.log(xhr);
                    console.log(errorThrown);
                    myApp.alert("Unknown error, please try again", "Login Failed");
                },

                complete: function(data) {
                    if(data.readyState == "0") {
                        console.log("unsent");
                    } else if(data.readyState == "4") {
                        console.log("done");
                    }   
                }

            });
        } return false;
    }

I have the config.xml file set up exactly as outlined in many previous answers: 我已经按照以前的许多答案中所述完全设置了config.xml文件:

<plugin name="cordova-plugin-whitelist" />
<access origin="http://my-server.com" />

etc...

Obviously disabling apple's App Transport Security is not going to be possible as I am not building the app, simply testing it on a Phonegap server and the Phonegap App. 显然,由于我不是在构建应用程序,而只是在Phonegap服务器和Phonegap App上对其进行测试,因此无法禁用Apple的App Transport Security。

But is this possibly to do with ATS preventing ajax requests to other domains from the Phonegap App itself? 但是,这可能与ATS阻止了Phonegap应用本身向其他域发出的Ajax请求有关吗? As I suppose it would require Phonegap to allow access to all domains, which probably isn't allowed on the app store! 正如我想的那样,这需要Phonegap允许访问所有域,而应用程序商店中可能不允许该访问!

That is my best guess as to what is happening. 这是我对发生的事情的最佳猜测。 Any ideas or workarounds? 有什么想法或解决方法吗?

新ios应用程序唯一的互联网解决方案是将后端移至https ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM