gpt4 book ai didi

javascript - ajax函数后访问对象

转载 作者:行者123 更新时间:2023-12-01 03:35:06 25 4
gpt4 key购买 nike

我有这个 ajax jquery 代码:

$("#serial_number").submit(function(e) {

var url = "/getVoucher"; // the script where you handle the form input.

$.ajax({
type: "GET",
url: url,
data: $("#serial_number").serialize(),
dataType: "json",
success: function(data)
{
console.log(data);

}
});

e.preventDefault(); // avoid to execute the actual submit of the form.
});

我从 console.log 得到这个: enter image description here

如何访问对象代码元素?

我尝试使用:data.Code也尝试了data.Description,但浏览器给我错误...如何在ajax代码中访问内部成功函数?

最佳答案

当您 console.log 一个变量时,控制台中的输出是它的内容,因此如果您仍然看到:

Object{ data: Object }

这意味着变量data内部有一个键data。尝试:

console.log( data.data.Code );

访问对象的内容。

关于javascript - ajax函数后访问对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44333699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com