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;
});
})

找不到错误开机自检

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

错误错误请求

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

你必须设置处理请求的服务器页面,如果你使用本地服务器,只需放置文件的NMAE即可,或者如果远程服务器放置了compltet url

最新更新