如何获取响应变量中的数据。在调试器中,我可以看到发回的所有数据(图像)但是如何从Object获取信息?
function getUserList() {
$.ajax({
url: "https://reqres.in/api/users",
type: "POST",
data: {
name: "paul rudd",
movies: ["I Love You Man", "Role Models"]
},
success: function(response) {
console.log(response);
}
});
}
我正在关注
的例子答案 0 :(得分:0)
以所需格式创建全局变量,并为其指定ajax post值。但首先确保对象属性然后创建对象。否则,您需要使用jquery extend()方法
来扩展它var userObject = {createdAt:"",id:"",movies:[],name:""};
function getUserList() {
$.ajax({
url: "https://reqres.in/api/users",
type: "POST",
data: {
name: "paul rudd",
movies: ["I Love You Man", "Role Models"]
},
success: function(response){
userObject = response;
console.log(userObject.createdAt+" "+ userObject.id);
}
});