一个简单的jQuery/AJAX查询

A simple jQuery/AJAX query

本文关键字:jQuery AJAX 查询 简单 一个      更新时间:2023-09-26

好吧,我有一段时间没有使用jQuery了,我觉得我犯了一些非常普通的错误,但似乎找不到它。

我想把html文件,使用ajax,到我的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具体。现在,当我点击按钮时,什么都没有发生。为什么?我是不是错过了一些基本的东西?

您的代码中有语法错误,您使用:而不是;

$(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