0

I have this code:

$('#' + textboxID).autocomplete({ delay: delay, source: ["cats", "dogs"] });

which works fine.

I want to use a webservice:

$('#' + textboxID).autocomplete({ delay: delay, source: webserviceURL});

This doesn't work. My webservice URL is /blah/blah.asmx/myMethod

The webservice definition is:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<string> myMethod(string term)
{
       // Logic here, return list of strings
}

The method never gets called. Can anyone point me in the right direction? I have other webservices in the same .asmx which work fine with other controls (other controls are using $.ajax to call them).

Edit: Getting closer, I now get a 500 error saying Request format is unrecognized for URL unexpectedly ending in '/myMethod'.

I think it's not treating my url quite right...

3
  • 1
    Have you used a tool like fiddler to see whats been sent/received by the browser? Can you hit the webservice address manually in the browser address bar? Commented Mar 24, 2011 at 16:45
  • I have no clue why I didn't use fiddler to start with, the problem is it is calling my webservice like a http request, with ?term=blah it would seem, will do more investigation! Commented Mar 24, 2011 at 16:52
  • sounds like you need to setup the ajax options. I imagine you need to set content type to JSON and make sure it is Post not Get. Additionally make sure you uncommented the line of code near the beginning of the web service class that allows the class to be exposed to client side script. Commented Mar 24, 2011 at 17:04

2 Answers 2

1

Here's a SO thread with a solution to using it with an Asp.net webservice:

jQuery AutoComplete (jQuery UI 1.8rc3) with ASP.NET web service

Sign up to request clarification or add additional context in comments.

2 Comments

Looks good but there is some kind of discrepancy between the webservice url parameter of $.ajax and the one you supply with autocomplete, I am not sure why it's treating them differently, but all my $.ajax calls work fine just as the example above
@SLC - the urls look the same as you are using. I think you need to configure the $.ajax options correctly and possibly add <webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webServices> to your web.config. See forums.asp.net/t/988377.aspx/2/…
0

Solved it, the key was in this question:

How do I set JQuery Autocomplete to POST instead of GET?

I put $.ajaxSetup( { type: "post" } ); before my .autocomplete line and it solved it. Most annoying they didn't put it as an option!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.