[英]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.