-3

The data passed is a JSON, i can't receive it using this

$.getJSON('http://agrimainfotech.com/test/json/json.php?isbn=9789381626344', function(data) {

         alert(JSON.stringify(data));

    });

I was able to use the same for another url and it works.

 $.getJSON('http://salespump.pumpstationstudios.com/app/services/getemployees.php', function(data) {

             alert(JSON.stringify(data));

        });

What is the difference between both the JSON passed and what should i do to make the first url work. I get an array in the server and then i use json_encode to make it in JSON format. but still this dosen't work.

hakre
  • 193,403
  • 52
  • 435
  • 836
hablema
  • 540
  • 1
  • 5
  • 17
  • This depends entirely on what the service returns. – jbabey Dec 17 '12 at 21:06
  • 11
    Is the second one a request on the same domain? You won't be able to do cross-domain GET requests without using JSONP. It looks like neither URL is configured to support JSONP. – Andrew Whitaker Dec 17 '12 at 21:06
  • 1
    Look at your js console for any errors. – aziz punjani Dec 17 '12 at 21:08
  • @azizpunjani : `Request URL: http://agrimainfotech.com/test/json/json.php?isbn=9789381626344 Request Method: GET Status Code: HTTP/1.1 200 OK` It doesn't show any error. the second one also gives the same. but it give the output also... @AndrewWhitaker : Both are different domains, i'm trying to get the data to my html app on localhost. The second one gives result. First one doesn't. – hablema Dec 17 '12 at 21:12

3 Answers3

2

First thing is 1st:

If you are not in the same domain use JSONP instead.

salespump.pumpstationstudios.com !== agrimainfotech.com
when it comes to cross domain requests. So it will fail if you try from one to the other.

Naftali
  • 144,921
  • 39
  • 244
  • 303
  • I tried this but but it gave no result, ` $.ajax({ url: 'http://agrimainfotech.com/test/json/json.php?isbn=9789381626344', dataType: 'jsonp', success: function(data){ alert(data); } });` – hablema Dec 17 '12 at 21:22
  • @hablema that is because your return data is **not** jsonp. – Naftali Dec 17 '12 at 21:23
  • ` $.ajax({ url: 'http://agrimainfotech.com/test/json/json.php?isbn=9789381626344', success: function(data){ alert(data); } });` This dosen't return anything at all... – hablema Dec 17 '12 at 21:24
  • @hablema how what should be done? [please read this](http://stackoverflow.com/questions/2067472/please-explain-jsonp) – Naftali Dec 17 '12 at 21:24
  • Can you help me make this work? http://jsfiddle.net/VagTe/ – hablema Dec 18 '12 at 07:23
0

You most likely have a cross domain issue. You could try to use jsonp if the server supports it.

Koen Peters
  • 12,798
  • 6
  • 36
  • 59
-1

Thanks everyone for mentioning about cross domain requests. It was new for me. I corrected it out by adding header('Access-Control-Allow-Origin: *'); in the sever php script. So now i can make my call from my phonegap app to the server.

hablema
  • 540
  • 1
  • 5
  • 17