0

I have seen many examples where JQuery autocomplete gets a json response from code behind. I seems a little counter productive to turn my list into json then back to an array of strings on client side. I have a web method in code behind that returns a List of the results that I want the autocomplete to use, is there a way to just call that method from JQuery (I am very very new to JQuery, actually just started messing with it tonight).

     <script type="text/javascript">
    $(document).ready(function () {
        $("#txtbox").autocomplete({
           source : 

Have no idea where to go from here...

9
  • 1
    Are using asp.net forms or MVC ? Commented May 10, 2012 at 5:58
  • stackoverflow.com/questions/1592048/… might help you Commented May 10, 2012 at 6:00
  • That question is for reading json response in JQuery, I am trying to see if there is a way to call a method that will return a simple string array or List right to JQuery Commented May 10, 2012 at 6:03
  • Remember that jQuery is JavaScript running on the client, while your web method is (presumably) C# running on the web server. In a conventional browser situation like this they are communicating via an http request from the client where the browser returns what is essentially a string. So no, you can't just call your web method directly from JavaScript (including jQuery) on the client. If you only want to convert the data once you could return html instead of JSON, though I'm not sure how that fits with the autoComplete jQuery plugin. Commented May 10, 2012 at 6:06
  • I had a feeling that was the answer, that sucks, on the bright side I always use XML because I know it well and I always avoid json because I don,t here's a good chance for me to learn , thanks Commented May 10, 2012 at 6:11

1 Answer 1

1

In Server side,

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public List<RetUsers> GetSomething()
{
//populate ur list here
  return list;
}

In Jquery,

 $("#txtbox").autocomplete({
           source : 'your url here'
Sign up to request clarification or add additional context in comments.

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.