0
我是新的AJAX和jQuery,我试图发布一条新的评论到'campground/campground_.id'
与我的ajax.js
文件,但我无法找到如何编写与URL的URL。 .. 我tryed:Ajax + jQuery发布网址与Id
$('#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;
});
})
错误错误请求
有人可以帮助我如何把它写正确?
你在哪里得到来自ID? – Dekel
''/ campgrounds /'+ campground._id'应该可以工作,假设'campground'对象被正确定义并且具有'_id'属性。在'$ .post'之前插入'console.log(campground)并告诉我们它在控制台中的含义。 – nurdyguy
这取决于'campground._id'究竟是什么?它是一个变量,是URL的一部分,通过模板语言从服务器端来的东西? – adeneo