一个简单的jQuery / AJAX查询

时间:2014-08-18 08:52:01

标签: javascript php jquery html ajax

好吧,我有一段时间没有做jQuery,我觉得我正在做一些非常平庸的错误,但似乎无法找到它。

我希望在文档准备就绪时使用ajax将html文件放到我的index.php中而不实际预加载网站。

所以,.php文件中的按钮:

  <button class="dropposts">Post a Comment..</button> 

和jQuery:

$(document).ready(function() {
    $('.dropposts').on('click', function() {
        $.ajax({ url: 'comment_form.html',
            dataType: 'html',
            success: function(response) 
            { $('.comment-form').html(response); }
        });
    }):
}):

这非常简单;我的文件位于根网站文件夹中,comment_form.html具体。现在,当我点击按钮时没有任何反应。为什么?我错过了一些非常基本的东西吗?

1 个答案:

答案 0 :(得分:1)

您的代码中存在语法错误,您使用:代替;

$(document).ready(function() {
    $('.dropposts').on('click', function() {
        $.ajax({ url: 'comment_form.html',
            dataType: 'html',
            success: function(response) 
            { $('.comment-form').html(response); }
        });
    });//changed here
}); //changed here