繁体   English   中英

带ID的Ajax + jQuery发布网址

[英]Ajax + jQuery post url with Id

我是AJAX和jQuery的新手,我正尝试使用ajax.js文件向'campground/campground_.id'发表新评论,但是我找不到如何使用ID编写URL的方法...我尝试过:

 $('#new-comment-form').submit(function(e){
     e.preventDefault();
     var comment = $(this).serialize();
     $.post('/campgrounds/' + campground._id, comment, function(data){
         debugger;
     });
 })

错误营地未定义

$('#new-comment-form').submit(function(e){

    e.preventDefault();
    var comment = $(this).serialize();
    $.post('/campgrounds/campground._id', comment, function(data){
        debugger;
    });
})

找不到错误的POST

$('#new-comment-form').submit(function(e){
    e.preventDefault();
    var comment = $(this).serialize();

    $.post('/campgrounds/<%= campground._id %>', comment, function(data){
        debugger;
    });
})

错误的错误请求

有人可以帮我如何正确编写吗?

您必须设置处理请求的服务器页面,如果您使用本地服务器只是将文件的nmae放置,或者如果远程服务器放置了compltet网址

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM