ajax实现点击不同的链接让返回的内容显示在特定div里,ajaxdiv


/* 以下代码通过ajax实现在一个web页面点击不同的链接,然后将返回的结果显示在该页面固定的div里。 */

<html> 
<head> 
<meta charset="UTF-8"> 
<title>Insert title here</title> 
<script language="javascript"> 
var http_request = false; 
function createRequest(url,objID){ 
http_request = false; 
if(window.XMLHttpRequest){ //非IE浏览器 
http_request = new XMLHttpRequest(); 
if(http_request.overrideMimeType){ 
http_request.overrideMimeType("text/xml"); 
} 
}else if(window.ActiveXObject){ //IE浏览器 
try{ 
http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
}catch(e){ 
try{ 
http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
}catch(e){} 
} 
} 
if(!http_request){ 
alert("无法创建XMLHTTP实例"); 
return false; 
} 
http_request.open("GET",url,true); 
http_request.send(null); 

var obj = document.getElementById(objID); 
http_request.onreadystatechange = function(){ 
if(http_request.readyState == 4){ 
if(http_request.status == 200){ 
obj.innerHTML = http_request.responseText; 
}else{ 
alert('您请求的页面发现错误!'); 
} 
} 
} 
} 
</script> 
</head> 

<body onload="createRequest('content1.html','show')"> 
<div align="center"> 
<a href="content1.html" onclick="createRequest('content1.html','show');return false;">no1</a> | 
<a href="content2.html" onclick="createRequest('content2.html','show');return false;">no2</a> | 
<a href="content3.html" onclick="createRequest('content3.html','show');return false;">no3</a> 
</div> 
<div id="show" align="center"></div> 
</body> 
</html>

怎利用jquery与ajax在点击某个div中显示不同页面

$("a.link").click(function(){
$.ajax({
//在每个连接后面加一个?ID=1

//获取这个ID来判断家中不同的内容

success:function(data){$('.show').html(data)}

})

})
 

我问一下,怎在JSP页面中实现点击某一超链接,然后在制定的div分区里面显示出来,用ajax实现

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>最原始的ajax写法</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">

//这个方法将使用XMLHTTPRequest对象来进行AJAX的异步数据交互
var xmlHttpRequest;

//用户名校验的方法
function verify() {
var success = createXMLHTTPRequest();
if (!success) {
return;
}
var userName = document.getElementById("userName").value;//获取用户名字
//2.注册回调函数
//注册回调函数时,之需要函数名,不要加括号
//我们需要将函数名注册,如果加上括号,就会把函数的返回值注册上,这是错误的
xmlHttpRequest.onreadystatechange = callback;

//3。设置连接信息
//第一个参数表示http的请求方式,支持所有http的请求方式,主要使用get和post
//第二个参数表示请求的url地址,get方式请求的参数也在url中
//第三个参数表示采用异步还是同步方式交互,true表示异步
//记住在url后面加上时间戳 ......余下全文>>
 

评论关闭