我需要协助。我正在尝试通过在互联网上找到的不同内容来完成此操作,但我无法理解该过程。
我有一个轮播,在注册后我的用户将被重定向到。
我想通过询问一些简单的问题作为输入来获取有关其个人资料的信息。
这是帕格代码
body
div(class='container fill')
div(id='myCarousel', class='carousel slide', data-ride='carousel', data-interval="false", data-wrap="false")
div(class='carousel-inner')
div(class='item active')
div(class='carousel-caption')
div(class='form-group', method='post')
h1(id='welcome') WELCOME
h1
| Tell us more about yourself
h2
| Pick any interest you like
label(for='shopping', class="radio-inline")
| Shopping
input(type='checkbox', id='round', name='interest_filter', value='2', checked=interest=='shopping')
div
label(for='travelling', class="radio-inline")
| Travelling
input(type='checkbox', id='round', name='interest_filter', value='3', checked=interest=='travelling')
div
label(for='musique', class="radio-inline")
| Musique
input(type='checkbox', id='round', name='interest_filter', value='4', checked=interest=='musique')
div
label(for='cooking', class="radio-inline")
| Cooking
input(type='checkbox', id='round', name='interest_filter', value='5', checked=interest=='cooking')
div
label(for='nature', class="radio-inline")
| Nature
input(type='checkbox', id='round', name='interest_filter', value='6', checked=interest=='nature')
div
label(for='arts', class="radio-inline")
| Arts
input(type='checkbox', id='round', name='interest_filter', value='7', checked=interest=='arts')
这是我不知道如何提供数据的地方
$('#matchme').click(function(){
var data = {};
$.ajax({
url: '/carousel',
type: 'POST',
cache: false,
data: JSON.stringify(data),
success: function(data){
alert('post success')
console.log(JSON.stringify(data));
}
});
});
这在我的app.js中(我将使用瀑布来思考数据并将其存储在我的数据库中)
app.post('/carousel', function (req, res) {
var data = {
interests: req.body.interest_filter,
orientation: req.body.orientation_filter,
age: req.body.age
},
});
我正在使用输入,因为您不能在转盘中放置表格。
到目前为止,我已经理解了这个概念,但是我已经使用Javascript了一个月了,而且遇到了麻烦,请问有什么帮助吗?
提前致谢 !
最佳答案
首先,您必须从用户那里收集所有信息,并在Ajax调用中传递该对象。除了空白对象外,我看不到请求期间传递的任何数据。之后,在服务器端,您可以像已编写的那样在req.body
中获取所有信息。
$('#matchme').click(function(){
var data = {name:'hola', info: 'info'};
$.ajax({
url: '/carousel',
type: 'POST',
cache: false,
data: JSON.stringify(data),
success: function(data){
alert('post success')
console.log(JSON.stringify(data));
}
});
});
关于javascript - 使用Ajax,jquery,Node.js和Express发布数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39470934/