使用jQuery和Ajax时出现IE错误

时间:2011-12-26 04:47:54

标签: jquery

所以我对使用jQuery非常新,我有一个脚本可以在点击加载更多时更新页面上的帖子。它在Chrome和Firefox中运行良好,但在IE中没有任何反应。有谁知道为什么?

jQuery脚本

function get(){
$("#acomment").empty().html('<img src="design/ajax-loader.gif" />');
$.post('loadmore.php', {id: document.form.id.value, number: counter, kind: document.form.kind.value},
    function(output){
        $('#acomment').html(output).show();
        counter+=5;
        $(document).ready(function() {
        $('html, body').animate({ scrollTop: $('#scrollspot').offset().top }, 1000);
        });
    });

}

调用该函数的按钮的脚本:

<form name="form" id="form" style='margin-top:10px'>
 <input type="hidden" name="kind" value="<?php echo $kind; ?>" />
 <input type="hidden" name="id" value="<?php echo $name; ?>" />
 <input type="button" value="Load More"  onClick="get()" style='width:35%' />

为什么它不起作用?我有点麻烦,问题与loadmore.php页面没关系

实施例: http://www.redarcadegames.com/topic/256

1 个答案:

答案 0 :(得分:0)

尝试改变这一点:

$.post('loadmore.php', {id: document.form.id.value, number: counter, kind: document.form.kind.value},

为:

$.post(
    'loadmore.php',
    {
        id: $("#form input[name='id']").val(),
        number: counter, 
        kind: $("#form input[name='kind']").val()
    },

并删除:

$(document).ready(function() {

所以你的整个代码是:

function get(){
    $("#acomment").empty().html('<img src="design/ajax-loader.gif" />');
    $.post(
        'loadmore.php',
        {
            id: $("#form input[name='id']").val(),
            number: counter, 
            kind: $("#form input[name='kind']").val()
        },
        function(output){
            $('#acomment').html(output).show();
            counter+=5;
            $('html, body').animate({ scrollTop: $('#scrollspot').offset().top }, 1000);
        }
    );
};