cordova android cross domain issue

﹥>﹥吖頭↗ 提交于 2019-12-12 01:27:54

问题


I have a small app made in cordova using beacons plugins and I want to send get request to a given page once beacons are discovered; I cannot send get request to my server using below code with jsonp; I tried different options but none of them worked;

$.ajax({
                    type: "GET", 
                    async: false,
                    dataType: 'jsonp', 
                    jsonp: 'callback', 
                    jsonpCallback: 'callbackFunction', 
                    url: "http://xxx",
                    crossDomain: true,
                    success: function(json){
                        alert("success");

                    },
                    error: function(){
                        alert("fail");
                    }
                });

回答1:


I have done something similar for my project. Check $.getJSON for more detailed explanation.

$.getJSON("http://domain/project/login.php?callback=JSON_CALLBACK&e=" + email + "&p=" + password, function() {
 console.log( "call successful" );
})
.done(function(data) {
    console.log(data.status);
 })
.fail(function() {
    console.log("Login.php's ajax reuqest failed.");
});

And the PHP response must have the $_GET['callback'] and mind the JSON format if you are sending some data in response:

echo $_GET['callback'] . '(' . "{'status' : 'success'}" . ')';


来源:https://stackoverflow.com/questions/28739845/cordova-android-cross-domain-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!