-1

I am using HTML5. I want to Call API with AJAX. but, not success to perform this. plz Help me how i Use this. I want Implement this code PhoneGap. Plz suggest me if any issue or best logic...

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.1.min.js"></script>
<script>
function loadXMLDoc()
{
alert("okey");
  $.ajax({
  type: 'GET',
  url:'http://www.internationalprom.com/mobile/ipa.php',
  data:{ft:'get',cat:'gallery',action:'top100'},
  success: onsuccess,
  error : onerror,


});
function onsuccess(data){
alert("success 1: "+ data );
// if got success then How i retrive Data from here?


}

function onerror(data){
alert("error 1 :"+data);
}

}
</script>
</head>

<body>

<h2>My CD Collection:</h2>
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">Get my CD collection</button>

</body>
</html>

Thanks...

MRT
  • 1,610
  • 15
  • 41

2 Answers2

0

I assume you know what info the server returns, but not the format.
The data the server returns is a JSON string (JavaScript Object Notation).
On the internet there are plenty of tutorials how to parse that, simplest is eval(JSONstring) but if you search Stackoverflow you'll find questions about eval called When is JavaScript's eval() not evil? and so on. That may give an idea about how recommended it is. Hope this helps you!

Community
  • 1
  • 1
11684
  • 7,356
  • 12
  • 48
  • 71
0

If you want to POST data you need to use HTTP POST not HTTP GET and also call json.stringify() on the JSON like this:

$.ajax({
    type: 'POST',
    url:'http://www.internationalprom.com/mobile/ipa.php',
    data: JSON.stringify({ft:'get',cat:'gallery',action:'top100'}),
    success: onsuccess,
    error : onerror
});
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
  • thanks for Quick reply... but, I check my old code and new code both.. both have same response.... – MRT Sep 15 '12 at 09:04
  • Chrome and Firefox have got response "status" is always "0" But, in Safari i have got response ""status" is "200" – MRT Sep 15 '12 at 09:05
  • @MRT are you getting this response status in success or error, or is it just firing complete? – Konstantin Dinev Sep 15 '12 at 09:08
  • @Dinev i getting response status in success but this is always "0". when i use on "Chrome" and "Mozila firefox" But, When i work or Safari this response Status is "200" in success. – MRT Sep 15 '12 at 09:20
  • Hey working properly My and your code both r fine But when i make sure Whitelist done then work properly... Cheers, – MRT Sep 15 '12 at 09:48