[英]Make 8 Ajax calls into 1
因此,我有一個包含八個類別的圖片庫。 每個類別都有400多個圖像,這些子類別由AJAX調用。 我在子類別中也有一個分頁系統。 目前我有8個ajax調用,這是無用的,所以我想通過給出2個論點將它們縮小為一個:'lap'告訴它在哪個頁面上,如果lap == 0或為null則給出正常頁面,否則,它會產生oldal +?page = +一圈。 “ Oldal”是第二個論點,它在第一個類別選擇中使用,它告訴瀏覽器打開哪個PHP文件(kepek_kat1.php或kepek_kat2 ... kepek_kat8.php)。 'Oldal'可以很好地打開類別,進入子類別,但是分頁不起作用。 這是我的8條代碼的代碼:
<div id="kepek">
<div class="kepkat"><a href="#amator" onclick="mutikat(null,'../php/kepek_kat1.php');"><img src="../img/kepkat/amator.jpg" height="130px" width="90px" alt="Amatőrök"/><br/>Amatőr</a></div></div> <!-- only showing the first selection -->
因此,第一個論據為空,這使它的頁面沒有分頁。
這是我的子類別代碼:
echo "<div class='lapozo'><a onclick='mutikat($page, '../php/kepek_kat1.php');' href='../html/blog.php#amator?page=$page'>$page</a></div>"; }
$ page處於循環中,它列出了當前所在的頁面,並顯示了頁面控件。
這是我的ajax電話:
function mutikat(lap, oldal)
{
//create XMLHttpRequest object
xmlHttpRequest = (window.XMLHttpRequest) ?
new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
//If the browser doesn't support Ajax, exit now
if (xmlHttpRequest == null)
return;
if(lap == 0 || lap === 0 || lap == null )
{
//Initiate the XMLHttpRequest object
xmlHttpRequest.open("GET", oldal, true);
}
else
{
xmlHttpRequest.open("GET", oldal + '?page=' +lap, true);
}
//Setup the callback function
xmlHttpRequest.onreadystatechange = StateChange;
//Send the Ajax request to the server with the GET data
xmlHttpRequest.send(null);
}
function StateChange()
{
if(xmlHttpRequest.readyState == 4)
{
document.getElementById('kepek').innerHTML = xmlHttpRequest.responseText;
}
}
有8個ajax調用。 請幫我!
非常感謝!
我知道您可以使用jQuery的$ .when.then();異步加載8個ajax調用。 職能...
這是一個例子:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.when(
$.getScript("http://domain.com/script_one.js"),
$.getScript("http://domain.com/script_two.js"),
$.getScript("http://domain.com/script_three.js"),
$.getScript("http://domain.com/script_four.js")
).then(
$(function() {
//work with downloaded scripts and their variables here
})
);
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.