问题
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