1
回答
关于jQuery AJAX的返回值
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

今天阅读锋利的jQuery,AJAX那章。在使用源码时返回奇怪的东西

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%out.println("Hello Ajax!");%>

HTML代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
function Ajax(){ 
	var xmlHttpReq = null;
	if (window.ActiveXObject){
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest){
		xmlHttpReq = new XMLHttpRequest();
	}
	if(xmlHttpReq != null){
		xmlHttpReq.open("GET","test.jsp",true);	
		xmlHttpReq.onreadystatechange=RequestCallBack;
		xmlHttpReq.send(null);
	}
	function RequestCallBack(){
		if(xmlHttpReq.readyState == 4){
				if(xmlHttpReq.status == 200){
					document.getElementById("resText").innerHTML = xmlHttpReq.responseText;
				}
		}
	}
}
</script>
</head>
<body>
<input type="button" id="" value="Ajax提交" onclick="Ajax();" />
<div id="resText" ></div>
</body>
</html>



JSP代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%out.println("Hello Ajax!");%>



举报
jjkmaze
发帖于3年前 1回/144阅
顶部