如何使用JSON与Web窗体我服务器的AJAX调用? [英] How do I server AJAX calls using JSON with Web Forms?

查看:108
本文介绍了如何使用JSON与Web窗体我服务器的AJAX调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道MVC控制器处于提供JSON格式的AJAX请求相当不错,但没有任何内置的ASP.NET功能,我可以使用这些类型的呼叫从一个普通的旧网页形式的网站?

I know MVC controllers are quite good at serving JSON formatted AJAX requests, but is there any built-in ASP.NET functionality I can use for these type calls from a plain old web forms site?

推荐答案

您可以使用内置的ASP.NET AJAX。

You could use built-in ASP.NET AJAX.

选项1 - 使用Web服务(如果你想要的功能,可重复使用):

Option 1 - use a web service (if you want the functionality to be reusable):

  • 创建一个Web服务(的.asmx)用[ScriptService]属性,
  • 一个添加到您的网页和Web服务添加到其服务集合,
  • 使用通过的ScriptManager在侑页面生成的JavaScript代理。

选项2 - 使用页面方法(如果你想在一个页面上的功能,而无需创建一个Web服务):

Option 2 - use page methods (if you want the functionality on a single page without creating a web service):

  • 定义静态方法在你的页面,添加[WebMethod]属性给他们,
  • 添加一个ScriptManager用的EnablePageMethods =真,
  • 使用PageMethods对象调用从JavaScript这些方法。

在这两种情况下的JSON将被用于数据传输。

In either case JSON will be used for data transfer.

下面是一个广泛的<一个href="http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/Ajax/tutorial-05-cs.aspx">tutorial一些code样本。

Here is an extensive tutorial with some code samples.

不过,ASP.NET AJAX经常被指责效率低下 - 例如,JS它产生往往是相当大的。因此,如果您关心性能,你要测试它彻底。

However, ASP.NET AJAX is often blamed for inefficiency - for instance, JS it generates tends to be rather large. So, if you are concerned with performance, you'd want to test it thoroughly.

您可能也看看这个线程:<一href="http://stackoverflow.com/questions/673075/net-ajax-calls-to-asmx-or-aspx-or-ashx">http://stackoverflow.com/questions/673075/net-ajax-calls-to-asmx-or-aspx-or-ashx

You might also have a look at this thread: http://stackoverflow.com/questions/673075/net-ajax-calls-to-asmx-or-aspx-or-ashx

这篇关于如何使用JSON与Web窗体我服务器的AJAX调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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