如何在Ajax中编写Web服务 [英] how to write web service in ajax

查看:68
本文介绍了如何在Ajax中编写Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

我正在使用ajax自动完成扩展器编写一个Web服务,但徒劳无功.随着事情的进展我逐渐淡了.我尝试了两天,但对jquery和ajax无效.
我的代码是:
在aspx页面上:

hi all..

I am writing a web service in using ajax autocomplete extender.but all in vain.I am fade up with the thing going on.i am trying for two days but nothing works with jquery and ajax.
my code is:
ON aspx page:

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
  <Services>
  <asp:ServiceReference  Path="~/WebService1.asmx" />
  </Services>
        </asp:ScriptManager>







<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
         <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" ServiceMethod="GetUsers"      ServicePath="~/WebService1.asmx"      TargetControlID="TextBox1" EnableCaching="true" CompletionInterval="10" />



我的Web服务代码.



My web service code.

[WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [ToolboxItem(false)]
  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  [System.Web.Script.Services.ScriptService]
  public class WebService1 : System.Web.Services.WebService
  {
      [WebMethod]
      public List<string> GetUsers(string prefixText, int count)
      {
          WebSolution.DAL.databaseDataContext DC = new WebSolution.DAL.databaseDataContext();
          var Customers = from p in DC.users
                          where p.firstName.Contains(prefixText)
                          select p.firstName;
          return Customers.ToList();
      }
  }




我能够调用Web服务方法并在浏览器中查找记录.
请告诉我.shld我必须更改web.config进行其他操作.否则任何答复都将得到兑现.您可以使用jquery向我建议.


问候




I am able to invoke the web service methods and find record in browser.
please tell me.shld i have to change the web.config for something.or anything else .any reply will be honored.U can suggest me soultion using jquery.


Regards

推荐答案

在起作用的方式是:
WCF数据服务和jQuery [
Here is on way that works:
WCF Data Services and jQuery[^]

Regards
Espen Harlinn


这篇关于如何在Ajax中编写Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆