日期:2014-05-16  浏览次数:20419 次

asp.net 使用Jquery ajax提交后台指定方法 为什么总是执行error 函数 为什么。。。跪求帮助
JS:
  <script language="javascript">
    function ImgChange(obj){
    var id=obj.id;
    alert(id);
         $.ajax({     
            type: "post",     
            url: "TestPage.aspx/SayHello",     
            contentType: "application/json;charset=utf-8",
      
            dataType: "json",
            success: function(theback) {     
              var objd = eval('(' + theback.d + ')').msg ;
                alert(objd);   
            },  
           error: function(err) {     
                alert("错误");     
            }     
        });     
    }        
    </script>
 <input type="button"  id="btnOK" value="GetDate" onclick="ImgChange(this)" /> 
后台:
  [WebMethod]
    public static String SayHello(String id)
    {
        return "{\"msg\":\"执行成功\"}";
    } 
不加data: "{\"id\":"\" + id + "\"}"这句后台设置无参, 就总是执行ERROR ,加上就更没反应了,,初学者求指导
------解决方案--------------------
在ajax的error处理事件中把错误信息显示出来,例如
error: function(XMLHttpReqeust){
      alert(XMLHttpRequest.responseText);
}
看返回什么错误信息
------解决方案--------------------
"TestPage.aspx/SayHello",     

应该使用ashx处理吧
------解决方案--------------------

url: "TestPage.aspx/SayHello",     

这个有问题。 url: "TestPage.aspx?type=SayHello",     
接收type判断是否SayHello 之后调用相应的函数。 
------解决方案--------------------
<%@ Page Language="C#" AutoEventWireup="true"  CodeBehind="validate.aspx.cs" Inherits="validate" %>


留着一行就行了
------解决方案--------------------
JS:
  <script language="javascript">
    function ImgChange(obj){
    var id=obj.id;
    alert(id);
         $.ajax({     
      &nbs