gpt4 book ai didi

javascript - 使用 Ajax、jquery、Node.js 和 Express POST 数据

转载 作者:行者123 更新时间:2023-11-28 05:34:18 25 4
gpt4 key购买 nike

我需要一些帮助。我试图按照我在互联网上找到的不同内容来完成此操作,但我无法理解这个过程。我有一个轮播,我的用户在注册后会立即重定向到该轮播。我想通过提出简单的问题作为输入来获取有关他们的个人资料的信息。这是帕格代码

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 中(我将使用 waterfall 来获取数据并将其存储在我的数据库中)

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 POST 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39470934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com