AJax技术

AJAX请求 $.post方法的使用(2)

字号+ 作者:H5之家 来源:H5之家 2015-10-16 12:33 我要评论( )

[backcolor=rgb(244, 244, 244) !important]protected void Page_Load(object sender, EventArgs e) { [backcolor=rgb(244, 244, 244) !important] if (!Page.IsPostBack) { [backcolor=rgb(244, 244, 244) !import

[backcolor=rgb(244, 244, 244) !important]protected void Page_Load(object sender, EventArgs e)
{
[backcolor=rgb(244, 244, 244) !important]  if (!Page.IsPostBack)
  {
[backcolor=rgb(244, 244, 244) !important]    if (Request["id"] != null && !string.IsNullOrEmpty(Request["id"].ToString()))
    {
[backcolor=rgb(244, 244, 244) !important]      Response.Write( GetData(Request["id"].ToString()));
    }
[backcolor=rgb(244, 244, 244) !important]  }
}

protected string GetData(string id)
[backcolor=rgb(244, 244, 244) !important]{
  string str = string.Empty;
[backcolor=rgb(244, 244, 244) !important]  switch (id)
  {
[backcolor=rgb(244, 244, 244) !important]    case "1":
      str += "This is Number 1";
[backcolor=rgb(244, 244, 244) !important]      break;
    case "2":
[backcolor=rgb(244, 244, 244) !important]      str += "This is Number 2";
      break;
[backcolor=rgb(244, 244, 244) !important]    case "3":
      str += "This is Number 3";
[backcolor=rgb(244, 244, 244) !important]      break;
    default:
[backcolor=rgb(244, 244, 244) !important]      str += "Warning Other Number!";
      break;
[backcolor=rgb(244, 244, 244) !important]  }
  return str;
[backcolor=rgb(244, 244, 244) !important]}



运行程序,结果如图:

[/url]

用httpwatcher拦截请求信息,当下拉框中选择数字时,可以截取到如下请求信息。

使用$.post方法时的截图:

[url=http://images.cnblogs.com/cnblogs_com/Johnny_Z/201206/201206171415148110.jpg]

通过上图我们可以看到在POST Data里面有参数,说明这是一次POST请求。

在服务器端状态有改变,或者是修改更新某些数据时多用POST请求。









来自群组: java开发组

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评