科尔多瓦Android的跨域问题科尔、多瓦、问题、Android

由网友(贱男配鸡如胶似漆)分享简介:我有一个小的应用程序中使用的信标插件科尔多瓦量身定做的,我要发送GET请求,一旦信标发现一个给定的网页;我无法发送GET请求,使用下面code与JSONP我的服务器;我尝试了不同的选项,但没有一次成功; $。阿贾克斯({键入:GET,异步:假的,数据类型:JSONP,JSONP:'回调',jsonpCallback:c...

我有一个小的应用程序中使用的信标插件科尔多瓦量身定做的,我要发送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 ['回调']。 ({地位:成功}。);
 
西班牙 法国南部深度16晚19日邮轮之旅 免费全国联运 邮轮阳台舱 陆地五星级酒店 蓝精灵村 梅诺卡岛 伊比萨岛 马拉加 米其林三星大餐

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

阅读全文

相关推荐

最新文章