zoukankan      html  css  js  c++  java
  • jquery ajax在aspx的调用

         前台代码

     1 <head runat="server">
     2     <title></title>
     3     <script src="../../Scripts/jquery-1.8.3.js" type="text/javascript"></script>
     4     <script type="text/javascript">
     5         $(document).ready(function () {
     6             $.ajax({
     7                 // url: "test_2.aspx",
     8                 url:"test_3.ashx",
     9                 data: { "Id": "3" },
    10                 type: "post",
    11                 dataType: "text",
    12                 beforeSend: function () {
    13                     alert("开始");
    14                 },
    15                 cache: true,
    16                 success: function (str) {
    17                     alert(str);
    18                 },
    19                 error: function (msg) {
    20                     alert("错误");
    21                 }
    22             });
    23         });
    24     </script>
    25 </head>
    View Code

        

         后台代码 aspx

     

     1 protected void Page_Load(object sender, EventArgs e)
     2         {
     3             string str = "false";
     4             if (!IsPostBack)
     5             {
     6                 string id = Request["Id"] != null ? Request["Id"].ToString() : "";
     7                 if (id != "")
     8                 {
     9                     str = "success";
    10                 }
    11                 else
    12                 {
    13                     str = "error";
    14                 }
    15             }
    16             Response.Write(str);
    17             Response.End();
    18         }
    View Code

        后台代码 ashx

     

     1  public void ProcessRequest(HttpContext context)
     2         {
     3             string str = "false";
     4             string id = context.Request["Id"] != null ? context.Request["Id"].ToString() : "";
     5             if (id != "")
     6             {
     7                 str = "success";
     8             }
     9             else
    10             {
    11                 str = "error";
    12             }
    13             context.Response.ContentType = "text/plain";
    14             context.Response.Write(str);
    15         }
    16 
    17         public bool IsReusable
    18         {
    19             get
    20             {
    21                 return true;
    22             }
    23         }
    View Code
  • 相关阅读:
    tomcat容器启动的启动过程(三)
    tomcat源码分析(二)启动过程
    tomcat源码分析(一)
    spring 整合redis
    redis win版安装
    java虚拟机存储区
    java代码块 静态、非静态
    Vulkan Tutorial 08 交换链
    Vulkan Tutorial 07 Window surface
    Vulkan Tutorial 06 逻辑设备与队列
  • 原文地址:https://www.cnblogs.com/qingzhibin/p/jquery_ajax_aspx_ashx.html
Copyright © 2011-2022 走看看