Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  138] [ 5]  / answers: 1 / hits: 16827  / 15 Years ago, tue, april 7, 2009, 12:00:00

Can jquery ajax code call a webservice from another domain name or another website?

Like this:



$.ajax({
type: POST,
url: http://AnotherWebSite.com/WebService.asmx/HelloWorld,
data: {'name':' + $('#price').val() + '},
contentType: application/json; charset=utf-8,
dataType: json,
success: function (msg) { alert(msg); }
});


And how should I config this webservice?


More From » asp.net

 Answers
3

you can use JSONP to make cross domain requests. with jquery you can make a jsonp request using the $.json function and specifying a callback in the url like so:



&callback=?


Actually, all you need is the question mark as the param value, the param name can be anything.



Only catch, is that the server you are making the request to must support jsonp



For more in depth information see this blog post about making jsonp work with the new york times json api:



http://notetodogself.blogspot.com/2009/02/using-jquery-with-nyt-json-api.html


[#99734] Thursday, April 2, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sam

Total Points: 711
Total Questions: 96
Total Answers: 107

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
sam questions
;