2013-10-13 73 views
0

我有一个页面的方法问题,我有一个ASP.net Web窗体AJAX内部服务器错误500

[WebMethod(true)] 
    public static int GetInt(int id){ 
      return 10; 
    } 

此页方法我称之为从JQuery的这样

$.ajax({ 
      type: "POST", 
      url: "webforms.aspx/GetInt", 
      data: "{id:'1'}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (msg) { 
      }, 
      error: function (err) { 
      } 
     }); 

这一切工作就好了,当我在服务器端放置一个断点时,它会触发,但是出于某种奇怪的原因,我在PageMethod返回后,我收到ajax调用的错误回调,并且永远不会成功!有任何想法吗。

我无法使用这个脚本管理器!我打开任何跨浏览器解决方案!

+0

看看实际的HTTP响应(在你的开发工具)和读取错误。 – SLaks

+1

尝试删除'dataType:“json”,' – Musa

+0

响应没有提供任何帮助。它有相同的错误信息。删除dataType也没有帮助。 – Ksliman

回答

0

我用你的代码,我没有问题。这里是我的确切代码:

WebForm1.aspx的

<head runat="server"> 
<title></title> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 

</div> 
</form> 

<script> 
    $.ajax({ 
     type: "POST", 
     url: "/WebForm1.aspx/GetInt", 
     data: "{id:'1'}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (msg) { 
      alert("SUCCESS: " + msg.d); 
     }, 
     error: function (err) { 
      alert("FAILURE"); 
     } 
    }); 
</script> 
</body> 
</html> 

WebForm1.aspx.cs中

using System.Web.Services; 


namespace WebApplication3 
{ 
public partial class WebForm1 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    [WebMethod(true)] 
    public static int GetInt(int id) 
    { 
     return 10; 
    } 
} 
} 
+0

感谢您的努力,这可能只是我本地安装的IIS进行的一些事情,我尝试过之后在开发服务器上按预期工作。这是最奇怪的事情,在这样一个简单的问题上吹了4个小时,我感到非常愚蠢。 – Ksliman

+0

你知道,我在使用断点时看到过这种情况。如果你查看你的代码太长时间并且遇到简历,你会得到ajax调用的错误函数。我不知道为什么,也许是暂停。很高兴我能帮上忙! – Zerkey