开发者

Passing .CS arraylist to JQuery

I am trying to create an autoc开发者_高级运维omplete text box based on an ArrayList from my main page's cs.

I am fairly new to JQuery and I am wondering what the best way to call the ArrayList from that page would be.

I feel like I have search all terms possible but all I can find are AutoComplete examples that either create the Array in a variable before it executes the script or it makes a vague reference to calling a URL.

Thanks for any information on this.

This is what I have so far in my newby experience.

<script type="text/javascript">
$(document).ready(function(){
$("#example").autocomplete("Requests.aspx.cs");
  });
</script>


A few things....

You don't call Request.aspx.cs (that is a code file that gets compiled). The client served page is Request.aspx, and that's what you need to call.

Since you're using the jQuery UI Autocomplete, the Request.aspx will need to respond with JSON data in the correct format (I believe it is a 3 field object with id, name and value).

Request.aspx will need to be setup to take in a parameter (I believe it is called term), do logic to lookup, and return the results of that lookup serialized as JSON. There are C# classes to help with JSON serialization.

You've got quite a few things you need to go figure out in order to achieve this. Hopefully the above will help get you started.


You can create a $.ajax request for the page Request.aspx, whose code behind should return your data. Then use the jQuery autocomplete.

Edit:
If you want to take the approach that Matthew has suggested, I would suggest checking out this page ASP.NET AJAX from ScottGu, as it describes a way to make server-side service calls directly from your javascript and should eliminate any mess JSON handling on your end.


May be you could expose some kind of restful service for this purposes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜