【问题标题】:Variable loses some value when used in Ajax API Call变量在 Ajax API 调用中使用时会丢失一些值
【发布时间】: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

【问题讨论】:

    标签: ajax api variables


    【解决方案1】:

    我找到了答案,控制台只是显示了 URL 的缩短版本,并且恰好切断了部分 tempid。谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 2012-10-19
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多