日期:2014-05-18  浏览次数:20886 次

用Jquery ajax 返回的值怎么是一整个页面
$(document).ready(function(){
  $("#tbUserName").bind("change",function(){

  $.ajax({
  type:"Get",
  url:"/AjaxPages/AjaxCode.aspx" ,
  dataType:"html",
  data:"userName="+$("#tbUserName").val()+"&flg=username",
// beforesend:function(XMLHttpRequest)
// {
// //$("#showResult").text("checking");
// },
  success:function(msg) //这个比较重要
  {
  //alert(msg);
  //$("#lbCheckUserName").show();
  $("#lbCheckUserName").val(msg);
  //$("[id$=lbCheckUserName]").html(msg);
  //$("#lbCheckUserName").css("color","red");
  //$("#showResult").html(msg);
  //document.getElementById("lbCheckUserName").innerHTML=msg;
  }
// complete:function(XMLHttpRequest,textstatus)
// {
// //
// },
// error:function()
// {
// //
// }
  });
   
  });
描述:用Jquery ajax 返回的值怎么是一整个页面,url:"/AjaxPages/AjaxCode.aspx",在这个页面处理完请求后,怎么只返回我要的结果,而不是整个页面的代码



------解决方案--------------------
AjaxCode.aspx
里面写
Response.Clear();
Response.Write("ok");
Response.End();
------解决方案--------------------
把你的那个AjaxCode.aspx上面的 HTML代码全部删除。留下 头部页面指令即可。
------解决方案--------------------
贴 /AjaxPages/AjaxCode.aspx.cs 的代码

我判断愿意应该是 response.write 完 没有 response.end

导致页面把HTML都返回过去了
------解决方案--------------------
在你想输出结果前想把response清空,然后把结果写道写页面,然后在结束response
这样返回的就是你的结果,否则会返回整个response,当然是页面全部信息

探讨

AjaxCode.aspx
里面写
Response.Clear();
Response.Write("ok");
Response.End();