$('#submit_id').click(function(){
function mark() {
$.ajax({
type: "POST",
url: "request1.PHP",
data: $('#form_id').serialize(),
cache: false,
success: function(data1){
}
});
}
function other() {
$.ajax({
type: "POST",
url: "request2.PHP",
data: $('#form_id').serialize(),
cache: false,
success: function(data2){
}
});
}
$.when(mark(), other()).done(function(data1, data2)
{
console.log(data1);
$(".results1").html(data1);
console.log(data2); // Result
$(".results2").html(data2);
});
});
我需要将返回的数据传递给变量,如:
console: undefined
解决方法:
您的代码应该像这样工作:
$.when(mark(), other()).done(function(data1, data2){
console.log(data1);
$(".results1").html(data1);
console.log(data2); // Result
$(".results2").html(data2);
});
function mark() {
return $.ajax({
type: "POST",
url: "request1.PHP",
data: $('#form_id').serialize(),
cache: false
});
}
function other() {
return $.ajax({
type: "POST",
url: "request2.PHP",
data: $('#form_id').serialize(),
cache: false
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。