【发布时间】:2021-12-03 17:42:30
【问题描述】:
我有一个问题,导致我的变量“tempid”在放入第二个 API 调用时丢失了一些值。正如您从我的图像中看到的,如果我将变量记录到控制台 (console.log(tempid)),它显示得很好。但是,一旦我将它放在 API 调用中,它就有一些价值,但不是全部。你能帮我解释一下为什么会发生这种情况吗?
[控制台示例][1]
$(document).ready(function() {
$.ajax({
url: "/api/Template/GetTemplates?classId=7ac62bd4-8fce-a150-3b40-16a39a61383d",
async:true,
dataType: 'json',
success: function(data) {
$(data).each(function (data) {
if (this.Name === "Name of Template"){
var tempid = this.Id
console.log (tempid)
var tempurl = "/api/V3/Projection/CreateProjectionByTemplate?id=" + tempid + "&createdById=703853d4-ffc4-fce3-3034-0b838d40c385"
$.ajax({
url: tempurl,
async: false,
dataType: 'json',
success: function(data) {
}
});
}
});
}
});
})
[1]: https://i.stack.imgur.com/gyesK.png
【问题讨论】: