0

I have made an Ajax call to one of my pages sitting in the server. When I am making the Ajax call, I am not getting the data. But instead I am getting status 200 OK with red font-color in the firebug. I am not able to figure out what the problem is.

I am making an ajax call to these api pages:

  [{"ID":"001","name":"Naidu","school":"Hyd","hobby":"cricket"}]

My ajax call is like:

  $.ajax({ url: 'http://something.com/api/name',
       data:{},
     type: 'post',
      dataType: "json",
    success: function(output) {
     //alert("SUCCESS");
      alert(output);
    }});
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
anand
  • 1,711
  • 2
  • 24
  • 59
  • 2
    I suggest against `alert()`, and instead suggest `console.log()`, you get something more meaningful. – Daedalus May 02 '14 at 06:22
  • Server Response code 200 OK just means no transaction errors were encountered. What does your code look like where it is being sent? Are you returning a value? – Brandon White May 02 '14 at 06:22
  • does the alert fire? Try echoing out the request on the server to make sure it's hitting the right place. – ioseph May 02 '14 at 06:22
  • In the code above, what's inside your `data`? – Jahm May 02 '14 at 06:23
  • if i type the url i am getting the response what i have shown in the first line – anand May 02 '14 at 06:31
  • I added the console.log() but i am not getting anything ... but if i remove the dataType:json , then by default it should return me at least Html response. As the whole data is inside Body tag when i checked it with firebug tool – anand May 02 '14 at 06:42

2 Answers2

0

Make sure API returns a status message when call is made.

Also retured output should be in json format. If you want to see exact output even if that is not json , remove DataType:"json" part from script and you should be able to see exact response.

Chances are that API isnt returning a message in one of the two cases or returned output is not json datatype.

KA.
  • 4,220
  • 5
  • 26
  • 37
  • See When i type the URL i am getting a blank page with the data i have mentioned in line 1. And also i checked that it's a valid Json Data. – anand May 02 '14 at 06:57
0

Make sure you are not doing cross-domain ajax.

Onur Okyay
  • 190
  • 1
  • 10
  • You cannot perform ajax request to another domain than the origin. To enable this you need to allow Access-Control-Allow-Origin: http://yourdomain-you-are-connecting-from.com/ on the target server. Please see: http://stackoverflow.com/questions/6871021/how-to-enable-cross-domain-request-on-the-server – Onur Okyay May 02 '14 at 06:58