[英]AJAX returns Undefined error when displaying an Array of objects using jQuery in PHP on console
I am trying to read a JSON through jQuery and AJAX and some objects like the SUM(amountbet) object
in the Array are returning as "undefined"
on console.我正在尝试通过 jQuery 和 AJAX 读取 JSON,并且某些对象(如数组中的SUM(amountbet) object
在控制台上返回为"undefined"
。
The above image shows the SUM(amountbet) object
as undefined on the console.上图显示SUM(amountbet) object
在控制台上未定义。
But when I am trying to access the "SUM(amountbet)" object it returns me "undefined" on console but when returning the horsename object the value is displayed perfectly.但是,当我尝试访问“SUM(amountbet)”对象时,它在控制台上返回“未定义”,但是当返回 Horsename 对象时,该值显示得很好。 What am i doing wrong here?我在这里做错了什么?
Here is my AJAX, jQuery code where i am trying to display each objects in that Array comming from an SQL Query:这是我的 AJAX、jQuery 代码,我试图在其中显示来自 SQL 查询的该数组中的每个对象:
$(document).ready(function(){
var racenumberr = $(this).attr("RaceNumber");
var data = new FormData();
data.append("RaceNumber", racenumberr);
$.ajax({
url:"ajax/horses.ajax.php",
method: "POST",
data: data,
cache: false,
contentType: false,
processData: false,
dataType: "json",
success: function(response) {
console.log("Horse Information Displayed In Array",response);
var len = response.length;
for (var i = 0; i < len; i++) {
var horsename = response[i].horsename;
var totalbetting = response[i].totalbetting;
var totalpayout = response[i].payout;
console.log("Horse Names",horsename);
console.log("Horse Payouts",totalbetting); // <-- object is displayed undefined on console
}
}
})
});
对象 totalbetting 未定义,SUM(amountbet) 创建 json 对象并将值转换为整数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.