【发布时间】:2018-09-01 06:53:19
【问题描述】:
大家好,我在使用 ajax 调用方面遇到了问题。
我有两个 ajax 调用,所以第一个 ajax 将数据发送到服务器,服务器检查并返回值,我希望返回值到另一个 ajax 调用,但似乎我在第二个 ajax 调用中没有传递任何内容。
第一次 Ajax 调用
function first(){
$.ajax({
url:window.location + '/first',
type: 'post',
data : $('form#first_form').serialize() //it will be like "name=Brad",
success: function(response){
consol.log(response.name); // I checked, and it returns "Brad"
second_ajax(response.name); //pass the returned value "Brad"
},error: function(){
}
});
}
第二次 Ajax 调用
function second(response_name){
$.ajax({
url:window.location + '/second',
type: 'get',
data : {username:response_name}//I am not sure how to write here, I want to send like 'username=Brad'
success: function(result){
},error: function(){
}
});
}
服务器
app.get('/second', (req, res) => {
//get the username from the second ajax call
var user_name = req.body.username;} //I am getting nothing here...
【问题讨论】:
标签: javascript jquery node.js ajax