I\'d like to call a .net webservice from another domain using only jquery.
What is the best way to do this? and are there any configuration changes I need to be awar
The browser does not allow XMLHTTPRequest calls across domains in its default configuration. You can change browser settings to make certain calls succeed, but this is considered bad practice.
In order to perform cross-domain requests, you can
Use the local server as a proxy to a remote server
This example uses a local ASP.NET Web Service to make a call to the Yahoo! Geocode service
Use a bridge
This example demonstrates how to create a bridge to flickr through the flickr API.
Would a better approach be to use: Jquery.getJSON?
See: JQuery.getJSON
This raises the question of how to output JSON compliant data using a webservice or similiar mechanism.
Here is an example:
$.post("CodersWS.asmx/DeleteBook", { id_book: parseInt(currBookID, 10) }, function(res) {
///do something with returned data: res
});
In the above example, I am calling a web service named CodersWS.asmx
, and the WebMethod inside it called DeleteBook
...I am also passing a parameter called id_book
.
Also don't forget to add this snippet to your web.config
, or else you wouldn't be able to access the web-service this way:
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
First, I'm not really sure if cross-site ajax as implemented in jquery will work in all browsers (firefox 3) just like that. Second, I assume you are talking about a SOAP web service. I'd rather not do that. It'll be very complicated to implement.
I think your problem is to make the crossdomain call. You have to change the data type of your jQuery request to jsonp
.
Take a look at this link
Generally, the answer is no, assuming you are talking about ASPX Web Services (basically a WebService hosted in an ASP.NET site).
This is the first hit on Google when searching for "webservice call jquery" which should give you more info:
http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/ you are using to host the web service).