0

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");
                    }
                });
marcinwal
  • 169
  • 10

1 Answers1

0

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'}" . ')';
Keval
  • 3,389
  • 2
  • 24
  • 41
  • Thanks but it did not not help; I tried and still have the same problem; it might be the cordova issue; – marcinwal Feb 26 '15 at 14:31
  • Can you give your whole code? I can help you. And where are you testing your app? – Keval Feb 27 '15 at 06:10
  • 1
    We managed to get it running; the problem was our local host; once we deployed the server to heroku all worked well; thank you very much for your help; – marcinwal Feb 27 '15 at 10:52