ajax的get 和post方式发送请求
2017-07-19 23:59
477 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script> <script type="text/javascript"> function valDateEmian(hag){ //createGetHttpRequst(hag.value); createPostHttpRequst(hag.value); } var xmlHttpRequest; function createGetHttpRequst(name){ xmlHttpRequest=new XMLHttpRequest(); //2调用回调函数 xmlHttpRequest.onreadystatechange=callBack; //3初始化xmlhttpreqost组件 xmlHttpRequest.open("GET","UserServlet?name="+name,true); //4发送请求 xmlHttpRequest.send(null); } function createPostHttpRequst(name){ xmlHttpRequest=new XMLHttpRequest(); xmlHttpRequest.onreadystatechange=callBack; xmlHttpRequest.open("POST","UserServlet",true); xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttpRequest.send("name="+name+"&opr=index"); } //设置回调函数 function callBack(){ if (xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200) { var date =xmlHttpRequest.responseText; document.getElementById("emain").innerHTML=date; } } </script> </head> <body> 邮箱 :<input type="text" onblur="valDateEmian(this)" /><span id="emain"> </span> 用户名 :<input type="text" /> <span id="emain"> </span> 密码 :<input type="text" /> <span id="emain"> </span> </body> </html>
相关文章推荐
- Ajax的GET与POST方式向服务器发送请求
- Ajax中的get和post两种请求方式的异同
- HttpClient详解,Java发送Http的post、get方式请求 --待整理
- 用java发送post、get请求(无参方式)
- android中post和get两种方式发送请求
- Extjs的ajax同步请求时post方式参数发送方式
- Ajax中的get和post两种请求方式的异同
- Ajax的请求方式GET/POST区别
- java发送post和get请求(1)---HttpURLConnection方式
- java发送http请求时设置请求方式(post,put,delete,get)
- java 用面向对象的方式发送http的GET和POST请求
- django中input type=submit 发送ajax 的post和get请求
- ajax中Post和Get请求方式的区别?
- Ajax以post方式传送带参的数据方式与get请求的不同
- android 向serverGet和Post请求的两种方式,android向server发送文件,自己组装协议和借助第三方开源
- Java发送HTTP的POST和GET方式请求
- java发送post和get请求(1)---HttpClient 方式
- java发送http的两种请求方式——get、post
- HTTP 请求方式: GET和POST的比较当发送数据时,GET 方法向 URL 添加数据;URL 的长度是受限制的(URL 的最大长度是 2048 个字符)。
- javascript/js的ajax请求方式:GET与POST