Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Ajax加载更多内容_Jquery_Ajax_Load - Fatal编程技术网

Jquery Ajax加载更多内容

Jquery Ajax加载更多内容,jquery,ajax,load,Jquery,Ajax,Load,我想从中加载一些内容 /page-0.html?到page=2,我的当前页面为 /page-0.html?到page=1。 这是我的密码: $(document).ready(function() { var page = 1; $.get('/page-0.html?to-page=' +page, function(html) { if(html) { $('#result').append(html); $('#more').text(

我想从中加载一些内容
/page-0.html?到page=2
,我的当前页面为
/page-0.html?到page=1。

这是我的密码:

    $(document).ready(function() {

    var page = 1;

    $.get('/page-0.html?to-page=' +page, function(html) {
    if(html) {

    $('#result').append(html);
    $('#more').text('Load More Post'); //add text "Load More Post" to button again
        } else {
            $('#more').text('No more Post to load'); // when last record add text "No more posts to load" to button.
        }
    $('#more').click(function() {
    $('#more').html('<img src="ajax-loader.gif"');
    page += 1;
    });
    }, 'json');

    });
$(文档).ready(函数(){
var-page=1;
$.get('/page-0.html?to page='+页面,函数(html){
如果(html){
$('#result').append(html);
$(“#更多”).text('Load more Post');//再次向按钮添加文本“Load more Post”
}否则{
$('#more').text('No more Post to load');//当最后一条记录将文本“No more posts to load”添加到按钮时。
}
$(“#更多”)。单击(函数(){
$('#更多').html('
html:

加载更多
如果单击“加载更多”按钮,则应将url
/page-0.html?更改为page=1到2。
是否可能

我是jquery新手。有人能帮我找到我的错误吗?

试试这个:

$(document).ready(function() {

    var page = 1;
    var getData;
    (getData = function() {
        $.get('/page-0.html?to-page=' +page, function(html) {
            if(html) {

                $('#result').append(html);
                $('#more').text('Load More Post'); //add text "Load More Post" to button again
            } else {
                $('#more').text('No more Post to load'); // when last record add text "No more posts to load" to button.
            }
        }, 'json');
    })();
    $('#more').click(function() {
        $('#more').html('<img src="ajax-loader.gif"');
        page += 1;
        getData();
    });
});
$(文档).ready(函数(){
var-page=1;
var-getData;
(getData=function(){
$.get('/page-0.html?to page='+页面,函数(html){
如果(html){
$('#result').append(html);
$(“#更多”).text('Load more Post');//再次向按钮添加文本“Load more Post”
}否则{
$('#more').text('No more Post to load');//当最后一条记录将文本“No more posts to load”添加到按钮时。
}
}“json”);
})();
$(“#更多”)。单击(函数(){
$('#更多').html('
我使用了getData函数作为一个函数,以便第一次自动命中请求,然后在以后单击“更多”时调用相同的函数。

HTH

谢谢,但它不起作用,因为您没有添加JQuery库Uncaught ReferenceError:$未在pen中定义。js:9请检查此项。您需要检查控制台或网络我已添加,但页面仍未加载打开chrome工具,请注意请求已被命中,但已被阻止。
$(document).ready(function() {

    var page = 1;
    var getData;
    (getData = function() {
        $.get('/page-0.html?to-page=' +page, function(html) {
            if(html) {

                $('#result').append(html);
                $('#more').text('Load More Post'); //add text "Load More Post" to button again
            } else {
                $('#more').text('No more Post to load'); // when last record add text "No more posts to load" to button.
            }
        }, 'json');
    })();
    $('#more').click(function() {
        $('#more').html('<img src="ajax-loader.gif"');
        page += 1;
        getData();
    });
});