views:

594

answers:

4

I've been looking for an example of a 1.1 web service getting called using jQuery. I'd like to call a web service and pass a few parameters to it.

Can someone point me in the right direction?

Thanks!

+1  A: 

Without more details on the web service, the generic answer is "use an AJAX call". The example below sends data in a JSON format, and retrieves JSON data back.

$.ajax({
  type: "POST",
  url: "theWebServiceURL",
  data: {'key1':'value1','key2':'value2'},
  dataType: /* depends on the return of the web service */,
  success: function(data) { /* do stuff here */ };
});

There are some peculiarities sometimes on sending the data, if you need to send data.

UPDATE: Given John Saunder's post, I thought I'd expand on the last sentence. ASP.NET v1.1 accepts (by default) HTTP GET, HTTP POST or HTTP SOAP. What one particular web service is set to accept basically dictates how the whole AJAX request must be sent to the web service. Using jQuery, you are mainly going to go to HTTP GET or HTTP POST. (Unless you get fancy and set processData: false. You then create and send your SOAP-formatted (XML) data and set content-type to text/xml, but I've never done this, so I am unsure of the details.)

alphadogg
A: 

I don't believe that .NET 1.1 Web Services suppoted JSON. That's stuff from back around 2002 or 2003. You'll have to use SOAP, or else upgrade, preferably to .NET 3.5 SP1 (the current release).

John Saunders
Does it not depend on the web service itself? I think you can HTTP POST or HTTP GET json-formatted data.
alphadogg
No. There was no JSON support back when .NET 1.1 was released. Only SOAP.
John Saunders
A: 

Here's a solid set to get you started:

You also want to review 3 mistakes to avoid when using jQuery with ASP.NET AJAX

Good luck! M

Matt Gardner
A: 

Just following up on this in case anyone else needs it in the future. I was able to call the 1.1 web service by using the ajax method and a POST:

$.ajax({
type: "POST",
url: 'PathToYourService.asmx/FunctionName',
data: 'foo1=value1&foo2=value&foo3=value',
dataType: "xml",
success: function(xml) {
    //do something with your data
}

});

Alex