【问题标题】:jQuery call to asp.net web method is not working对 asp.net web 方法的 jQuery 调用不起作用
【发布时间】:2014-08-23 13:33:05
【问题描述】:

我有一个像下面这样的 asp.net 网络方法

[WebMethod]
public string getDate() 
{
   return DateTime.Now.ToString();
}

我的 jQuery ajax 调用如下

$.ajax({
   type: "POST",
   url: "jqueryAjax/Default.aspx/getDate",
   data: "{}",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   error: function (XMLHttpRequest, textStatus, errorThrown) 
   {
      alert(errorThrown+"what's wrong?"+XMLHttpRequest);
   },
   success: function (msg) 
   {
      alert(msg);
      // Do something interesting here.
   }
});

由于某种原因,我的 jQuery ajax 错误处理程序被调用。成功方法没有调用。

我们将不胜感激。

谢谢

【问题讨论】:

  • errorThrown 的值是多少?
  • @JustinIurman 抛出的错误是 [object Object]
  • 嗯,我的意思是,你得到什么错误信息进入那个对象?另外,您是否通过domain.com/jqueryAjax/Default.aspx/getDate 访问您的网络方法?
  • @JustinIurman 我该如何检查?
  • console.log(errorThrown); 甚至更好的console.dir(errorThrown); 并查看浏览器的控制台以获取您的对象

标签: jquery asp.net ajax webmethod


【解决方案1】:

你的网络方法应该是静态的

[WebMethod]
public static string getDate() 
{
   return DateTime.Now.ToString();
}

【讨论】:

  • 知道如何从 web 方法返回 xml 并在 javascript 或 jquery 中解析
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 2015-09-05
  • 1970-01-01
相关资源
最近更新 更多