ASP.Net之JS之AJAX之Post请求
2017-08-22 16:44
471 查看
一、AjaxPostDemo.aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxPostDemo.aspx.cs" Inherits="WebApp.AjaxPostDemo" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="js/jquery-1.7.1.js"></script> <script type="text/javascript"> $(function () { $("#btnPost").click(function () { var xhr; if (XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("post", "GetDate.ashx", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("name=zhangsan&pwd=123"); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { alert(xhr.responseText); } } } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" value="获取数据" id="btnPost" /> </div> </form> </body> </html>二、GetDate.ashx代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApp { /// <summary> /// GetDate 的摘要说明 /// </summary> public class GetDate : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(context.Request["name"]); } public bool IsReusable { get { return false; } } } }三、效果演示
相关文章推荐
- asp.net 使用ajax请求地址接口数据 ajax返回类型是json js get post请求数据
- asp.net+ajax的Post请求实例
- MVC4 AspNet MVC下的Ajax / 使用微软提供的Ajax请求脚本 [jquery.unobtrusive-ajax.min.js]
- 【笔记】Asp.Net WebApi对js POST带参数跨域请求的支持方案
- ajax应用asp.net的post请求
- iis 7 asp.net ajax post 请求字节过大报错问题解决办法
- 修改asp.net的Ajax变更为post请求的历程
- ASP.Net之JS之AJAX之Get请求
- asp.net+ajax的Post请求实例
- asp.net Ajax Post 请求一般处理程序
- ASP.NET之通过JS向服务端(后台)发出请求(__doPostBack is undefined)
- 基于.NET三种Ajax技术的运用——原生js、ASP.NET Ajax和.NET回调技术
- js原生ajax请求get post笔记
- js+ asp.Net ajax开发163邮箱效果(列表底色、多选拖动等)--checkBox多选
- ASP.NET MVC 实现AJAX跨域请求方法《1》
- ASP.NET:为 AJAX 请求添加客户端事件
- asp.net+ajaxfileupload.js 实现文件异步上传代码分享
- asp.net ajax 无法弹出JS对话框
- 简单ASP.NET AJAX 客户端应用:用JS直接调用WebServices方法
- ASP.NET MVC 实现 AJAX 跨域请求