科尔多瓦Android的跨域问题 [英] cordova android cross domain issue

查看:113
本文介绍了科尔多瓦Android的跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的应用程序中使用的信标插件科尔多瓦量身定做的,我要发送GET请求,一旦信标发现一个给定的网页;我无法发送GET请求,使用下面code与JSONP我的服务器;我尝试了不同的选项,但没有一次成功;

  $。阿贾克斯({
                    键入:GET,
                    异步:假的,
                    数据类型:JSONP,
                    JSONP:'回调',
                    jsonpCallback:callbackFunction参数,
                    网址:HTTP:// XXX,
                    跨域:真正的,
                    成功:函数(JSON){
                        警报(成功);

                    },
                    错误:函数(){
                        警报(失败);
                    }
                });
 

解决方案

我已经做了类似的为我的项目的东西。检查 $ .getJSON 获得更详细的解释。

  $的getJSON(HTTP://domain/project/login.php回调= JSON_CALLBACK急症=+电子邮件+&安培; P =+密码功能( ){
 的console.log(叫成功);
})
.done(功能(数据){
    执行console.log(data.status);
 })
.fail(函数(){
    的console.log(login.php中的Ajax reuqest失败。);
});
 

和PHP的反应必须有 $ _ GET ['回调'] 和心灵的JSON格式,如果您要发送一些数据,以响应:

 回声$ _GET ['回调']。 ({地位:成功}。);
 

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");
                    }
                });

解决方案

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'}" . ')';

这篇关于科尔多瓦Android的跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆