jQuery 返回链接不起作用。我使用过 jQuery 和基本的 Ajax 功能。我的 jQuery 从文件返回链接Links_ajax.php
。
我给出了代码示例。
GetCustomerData.php 有:
<html>
<script type="text/javascript">
<script src="ajax.js" type="text/javascript">
$(function() {
.....
$.ajax({
type: 'POST',
url: 'Links_ajax.php',
data: 'category='+category ,
success: function(data){
$("#response").html(data);
}
});
}
......
}
...
<! Links return here
<div id="response">
</div>
</html>
<?
echo "Some Code";
?>
....
我的 Links_ajax.php 有以下代码
....
echo '<a href="getCustomerData.php?id=10" onclick="requestCustomerInfo();return false;">show me </a>';
echo '<a href="getCustomerData.php?id=11" onclick="requestCustomerInfo();return false;">show me </a>';
....
现在我来到主页getCustomerData.php。我使用了从 Links_ajax.php 返回链接的 Ajax 功能。
.....
所以,我的 ajax.js 有以下 Ajax 脚本。
var url = "GetCustomerData.php?id="; // The server-side script
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.status == 200) {
var results = http.responseText;
document.getElementById('divCustomerInfo').innerHTML = results;
}
}
}
function requestCustomerInfo(event) {
if(event &&event.preventDefault) event.preventDefault();
else if (window.event && window.event.returnValue)
window.eventReturnValue = false;
var sId = 10;
http.open("GET", url + escape(sId), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp){
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP object
……
现在我来解决问题了。当我执行 GetCustomerdata.php 时,我能够从 ajax.JQuery 获取所有链接。单击它后,我需要一个基本的 Ajax 功能,因为加载了相同的<div>
</div>
. 但是,即使我完成了,我也无法查看它。我的代码有什么问题吗?还是我必须使用任何其他功能?