javascript - [JS][AJAX] 第二个 ajax 不起作用。为什么?
问题描述
我有一点问题 :) 第一个 ajax 返回正确的值。然后我从第一个答案中提取文本,我想将此文本发送到另一个 ajax 文件。但第二个发送一个空值。为什么?所以这是我的代码:
var fileName = "record.wav";
var formdata = new FormData();
formdata.append('file', blob);
$.ajax({
url: "sendFileAudio.php",
type: 'POST',
data: formdata,
// async: true,
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$("#loaderStt").show();
},
success: function(data) {
console.log(data);
var messagesContainerOther = $(".messages");
messagesContainerOther.append(
data
);
var audioRsp = $(data).text();
var pytanie = audioRsp.valueOf();
// alert(typeof audioRsp);
document.getElementById("wiadomosc").innerHTML = pytanie;
// var pytanie = $("#wiadomosc").text();
$.ajax({
url: "sendMessageSamara.php",
type: 'POST',
data: pytanie,
beforeSend: function() {
$("#loader").show();
},
success: function(data) {
// console.log(data);
// alert("2"+ref);
console.log("poszło");
console.log(pytanie);
var messagesContainerOther = $(".messages");
messagesContainerOther.append(
data
);
messagesContainerOther.finish().animate({
scrollTop: messagesContainerOther.prop("scrollHeight")
},
250
);
},
complete: function(data) {
$("#loader").hide();
},
});
},
complete: function(data) {
$("#loaderStt").hide();
},
});
解决方案
您没有在第二个请求中发送键/值对,仅发送一个值
改变
data: pytanie
到
data: {somePropertyName: pytanie}
并在 php 中接收:
$_POST['somePropertyName'];
推荐阅读
- css - 尽管@media 在源 .css 中,但 CSS 媒体标签不适用于生产,而是在本地工作
- mysql - 排名输出中的排名系统差距
- oracle - 如何使用输入用户的列名将数据插入数据库
- regex - 正则表达式从字符串中提取不一致的邮政编码
- mysql - 使用 Excel 进行 MySQL 查询
- android - 组合图(条形图和折线图)+ xAxis.setValueFormatter
- c# - 如何更改 UITypeEditor 按钮上的“...”文本?
- swift - 如何在 Swift 中获取数组的中间索引?
- javascript - 不进入 JavaScript 'for' 循环(用于添加到表中)
- java - 如何为 jar 中的所有文件授予 CHMOD 0755 权限