Javascript jQueryAjax帖子:从响应中获取值

Javascript jQueryAjax帖子:从响应中获取值,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有以下jQuery AJAX调用: $.ajax({ method: "POST", url: "/Agenda/Template", dataType: 'json', data: { "templateId": templateSelect.options[templateSelect.selectedIndex].value }, complete: function (data) {

我有以下jQuery AJAX调用:

    $.ajax({
        method: "POST",
        url: "/Agenda/Template",
        dataType: 'json', 
        data: { "templateId": templateSelect.options[templateSelect.selectedIndex].value },
        complete: function (data) {
            for (var key in data) {
                var value = data[key];
                alert("key: " + key, "value: " + value);
            }
        }});
我知道返回数据具有以下属性:

  • 模板ID
  • 模板名称
  • 网址
然而,就我的生命而言,我无法接近它们


我的提醒显示了很多不同的键。。。Promise、Done等。我只是找不到我的值。

这听起来像是ajax返回Promise对象,所以您可以使用函数:

$.when( 
    $.ajax({
        method: "POST",
        url: "/Agenda/Template",
        dataType: 'json', 
        data: { "templateId": templateSelect.options[templateSelect.selectedIndex].value }
    })
).then(function( data, textStatus, jqXHR ) {
    for (var key in data) {
        var value = data[key];
        alert("key: " + key, "value: " + value);
    }
});

试试这个。这可能对你有帮助

 $.ajax({
        method: "POST",
        url: "/Agenda/Template",
        dataType: 'json', 
        data: { "templateId": templateSelect.options[templateSelect.selectedIndex].value },
        success: function (data) {
            $.each(data,function(key,value) {
                console.log("Key : " + key  +  " value : " + value);
            });
        }
 });

当您对console.log进行操作时,数据会显示什么?@guratio键/值对列表,带有“承诺”、“完成”等内容。找不到我的数据。您能在操作系统中显示吗?您的代码不应该返回一些“承诺”或“完成”响应。我们需要一些进一步的信息,因为问题不在您的代码中。试试JSON.stringify(data,null,2)并告诉我们它看起来像什么。你确定这个ajax需要数据类型:“JSON”吗?已经试过了。它给了我相同的值。我只需要找到我的数据就可以了。