2

I want to call this WS http://www.webservicex.net/country.asmx?op=GetCountries

What is the best possible way to do it using jQuery

Musa
  • 315
  • 2
  • 4
  • 15
  • http://stackoverflow.com/questions/861784/how-to-call-a-web-service-from-jquery/861808#861808 –  May 19 '09 at 08:59

3 Answers3

3

If you want to make Cross-Domain calls with jQuery you'll either have set-up a "proxy" file on your own server which fetches the remote contents and sends them to local jQuery or you need the webservice to support JSONP

duckyflip
  • 16,189
  • 5
  • 33
  • 36
2

You could do this using the ajax method (either POST or GET). Here i use GET as all remote (not on the same domain) requests should be specified as GET. I also provide a callback method to show the result as an alert.

$.ajax({
   type: "GET",
   url: "http://www.webservicex.net/country.asmx",
   data: "op=GetCountries",
   success: function(msg){
     alert( "Result: " + msg );
   }
 });
Fraser
  • 15,275
  • 8
  • 53
  • 104
  • I did it exactly as you suggested and got the 'Permission Denied' error – Musa May 19 '09 at 09:19
  • Ah ok, use the jQuery.getJSON method instead like duckyflip stated: http://docs.jquery.com/Ajax/jQuery.getJSON – Fraser May 19 '09 at 16:11
1

Maybe this will help:

jeroen.verhoest
  • 5,173
  • 2
  • 27
  • 27