日期:2014-05-17  浏览次数:20434 次

jquery post 回调函数那里出了问题,急,
就是在jquery中post功能,在完成调用函数后,回调函数却没有发挥作用,为什么,哪里出了问题。在解释清楚点,就是处理文件的返回值"success"在没有刷新页面的前提下没有出现在前台页面,直接上代码
HTML code
<script language="javascript" type="text/javascript">
      $(function(){
        $("#Button1").click(function(){          
              $.post("text.aspx",{Action:"post",timeBegin:$("#TextBox1").val(),timeEnd:$("#TextBox2").val()}
            ,function(data){            
                  document.getElementById("mydiv").innerHTML="<font color='red'>"+ data + "</font>";
            },"json" );                        
        });
      });       
    </script>
 <form id="form1" runat="server">
    <div>
        起始日期:<asp:TextBox ID="TextBox1" class="mydate"  runat="server"></asp:TextBox>
        截止日期: <asp:TextBox ID="TextBox2" class="mydate" runat="server"></asp:TextBox>
    </div>
    <input id="Button1" type="button" value="提交" />
    </form>
    <div id="mydiv">
    </div>



C# code

protected void Page_Load(object sender, EventArgs e)
    {        
        string timeBegin = Request.Form["timeBegin"];
        string timeEnd = Request.Form["timeEnd"];                
        Response.ContentType = "text/plain";
        Context.Response.Write("success!");        
        Response.End();
    }



------解决方案--------------------
JScript code


 $(function(){
        $("#Button1").click(function(){          
              $.post("text.aspx",{"Action":"post","timeBegin":$("#TextBox1").val(),"timeEnd":$("#TextBox2").val()}
            ,function(data){            
                  document.getElementById("mydiv").innerHTML="<font color='red'>"+ data + "</font>";
            },"json" );                        
        });
      });

------解决方案--------------------

"json" 你的反回值不是JSON 换成"text" 看看