Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.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
Javascript 一个简单的jQuery/AJAX查询_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 一个简单的jQuery/AJAX查询

Javascript 一个简单的jQuery/AJAX查询,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,好吧,我有一段时间没有做jQuery了,我觉得我犯了一些非常平庸的错误,但似乎找不到它 我希望在文档准备就绪时,使用ajax将html文件放入index.php,而不实际预加载网站 因此,.php文件中的按钮: <button class="dropposts">Post a Comment..</button> 这是非常简单的,;我的文件位于根站点文件夹中,具体位置为comment\u form.html。现在,当我点击按钮时,什么也没发生。为什么?我遗漏了一些

好吧,我有一段时间没有做jQuery了,我觉得我犯了一些非常平庸的错误,但似乎找不到它

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

因此,.php文件中的按钮:

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

这是非常简单的,;我的文件位于根站点文件夹中,具体位置为
comment\u 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

您应该使用jQuery加载:删除
数据类型:html
,然后再试一次。也许冒号正在破坏它?您应该使用分号关闭最后2个函数…您是否在浏览器错误控制台中查找错误?将来,请在访问StackOverflow之前学习简单的调试技术。当你的JS不工作时,你应该做的第一件事就是检查浏览器错误控制台,看看它是否报告了任何错误。是的,那将是一个语法错误(如果这是在真实代码中,而不仅仅是发布的问题中的工件)。OP甚至懒得在错误控制台中查找错误吗?是的,就这么简单。谢谢
$(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