![](/img/trans.png)
[英]Why does the response of AJAX with “_blank” work for first function, but not the second function?
[英][JS][AJAX] second ajax does not work. Why?
我沒有什么大問題:)第一個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'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.