jQuery返回鏈接不起作用。我已經使用jQuery和基本的Ajax功能。我的jQuery返回文件Links_ajax.php
的鏈接。jQuery Ajax返回鏈接不工作
我給的代碼樣本。
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獲取所有鏈接。 而在點擊,我需要加載以來同<div>
</div>
一個基本的Ajax特性。但即使完成,我也無法查看它。 我的代碼有什麼問題嗎?或者我必須使用任何其他功能?