1

所以我有一个包含八个类别的图片库。每个类别有 400 多个图像,这些子类别由 AJAX 调用。我在子类别中也有一个分页系统。目前我有 8 个 ajax 调用,这是没用的,所以我想通过给出 2 个参数将它们缩小为一个:'lap' 告诉它它在哪个页面上,如果 lap == 0 或 null 它给出正常页面,否则它会给出 oldal+?page= + lap。'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 调用。请帮我!

非常感谢!

4

1 回答 1

1

我知道你可以使用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>
于 2012-07-02T20:08:20.843 回答