[英]Wrong data received in javaScript using AJAX
我在file.js中進行了多次調用AJAX,調用具有以下格式:
file.js
$.post('functions.php',{consulta: 'tbl_Cours', action: {"ask_query_field":variable1}).val()}, function(res1){
if (res1){
//do something
}
//Second call
$.post('functions.php',{consulta: 'tbl_Cours', action: {"ask_query_field":variable2}}, function(res2){
if(res2){
//do something
}
//third call
$.post('functions.php',{consulta: 'tbl_Cours', action: {"ask_query_field":variable3}}, function(res3){
if(res3){
console.log(res3);
}
});
});
});
因此,第一次調用和第二次調用返回非常好,我調用了相同的文件functions.php和相同的函數。 但是在第三個調用中,我得到了一個數據,但它與從服務器服務器php發送的數據不同。
我在php中看到了日志,並顯示返回以下內容:
從PHP日志
[30-Jan-2018 11:06:50 America/Chicago] Array
(
[tema] => Tema 1 .- Introducción y definiciones
[pk_tema] => 3
[cantidad] => 1
)
[30-Jan-2018 11:06:50 America/Chicago] Array
(
[tema] => Tema 2 .- Posiciones y valoraciones
[pk_tema] => 4
[cantidad] => 3
)
[30-Jan-2018 11:06:50 America/Chicago] Array
(
[tema] => Tema 3 .- Practicas y actividades
[pk_tema] => 5
[cantidad] => 3
)
接下來,在Javascript中,我看到我收到的內容和數據不同
>> {0: {…}, 1: {…}, 2: {…}}
0:{tema: "Tema 1 .- Introducción y definiciones", pk_tema: "3", cantidad: "1"}
1:{tema: "Tema 2 .- Posiciones y valoraciones", pk_tema: "4", cantidad: "4"}
2:{tema: "Tema 3 .- Practicas y actividades", pk_tema: "5", cantidad: "3"}
pk_tema:4現在在function.js中有3的候選資格 :3。
因此,我不確定我使用php7和jQuery v1.12.4的問題是什么。 在谷歌瀏覽器中
感謝@bigless,因為我沒有檢查開發人員的所有工具,所以我收到了JavaScript中正確的數據,但是我不確定為什么它會隨着時間而變化,所以我將永遠不會使用變量res3的兩倍,而是使用它的信息。有變化。 非常感謝您的時間。
0:{tema: "Tema 1 .- Introducción y definiciones", pk_tema: "3", cantidad: "1"}
1:{tema: "Tema 2 .- Posiciones y valoraciones", pk_tema: "4", cantidad: "3"}
2:{tema: "Tema 3 .- Practicas y actividades", pk_tema: "5", cantidad: "3"}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.