/*AJAX异步提交*/ /*1.声明一个AJAX全局变量*/ var ajaxRequest; function checkAjAx() { /*2.创建XMLHttpRequest*/ ajaxRequest=new XMLHttpRequest(); /*3.配置请求对象*/ var url="user.do?uname="+$("uname").value()+"times="+new Date().getMilliseconds(); /*解决乱码问题,后台用URLDecoder.decode(uname,,""utf-8)*/ url=encodeURI(url); url=encodeURI(url); /*开启请求*/ /* /!*post提交加以下代码*!/ ajaxRequest.setRequestHeader("Content-Type","appplication/x-www-form-urlencoded");*/ ajaxRequest.open("GET",url,true); /*4.准备发送状态--ajax*/ ajaxRequest.onreadystatechange=function () { /*判断状态为AJAX,正常响应*/ if (ajaxRequest.readyState==4&&ajaxRequest.status==200){ $("result").innerHTML=ajaxRequest.responseText; } } /*get方法send(null)填null,post方法填变量send(num)*/ ajaxRequest.send(null); } }
原文地址:https://www.cnblogs.com/2070393244com/p/9445417.html
时间: 2024-10-08 02:11:12