jQuery リターン リンクが機能していません。jQuery と基本的な Ajax 機能を使用しました。私のjQueryは file からリンクを返します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>ます。しかし、私はそれを見ても見ることができません。私のコードに何か問題がありますか? または、他の機能を使用する必要がありますか?