jQuery的阿贾克斯楼盘Asp.Net 2.0楼盘、阿贾克斯、jQuery、Net

2023-09-10 19:05:40 作者:一朵菊花赢天下

我总是看到code像这样的博客:

  $。阿贾克斯({
                    键入:POST,
                    的contentType:应用/ JSON的;字符集= UTF-8,
                    网址:WebService.asmx / HelloWorld的,
                    数据: {},
                    数据类型:JSON,
                    成功:函数(MSG){
                        警报(msg.d);
                    }
                });
 

但我认为这仅仅是与asp.net 3.5中运行。我无法与2.0运行它。我怎么可以用这样这些C $ CS $在我的应用程序?

解决方案

您需要将此属性添加到您的网络服务器类

  [System.Web.Script.Services.ScriptService]
公共类服务:System.Web.Services.WebService
 
ASP.NET2.0

和这个属性给函数的

  [ScriptMethod(ResponseFormat = ResponseFormat.Json)
 

您在技术上不指定responseformat,因为它根据响应 该格式您在请求中指定。而你的必须的指定要求的格式。

问候 氏/ P>

I always see the code like this in the blogs:

$.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "WebService.asmx/HelloWorld",
                    data: "{}",
                    dataType: "json",
                    success: function(msg) {
                        alert(msg.d);
                    }
                });

But I think this is run only with asp.net 3.5. I couldn't run it with 2.0. How can I use such these codes in my Applications?

解决方案

You need to add this attribute to your webserver class

[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService

and this attribute to your functions

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

You don't technically need to specify the responseformat, as it responds according to the format you specify in the request. And you must specify a format in the request.

Regards K