【问题标题】:jQuery OrgChart how to set ajax request headersjQuery OrgChart 如何设置 ajax 请求标头
【发布时间】:2017-09-27 21:36:47
【问题描述】:

使用https://github.com/dabeng/OrgChart 如何在 ajax 调用中设置请求标头

我正在尝试以下方法

$('#chart-container').orgchart({
            'data' : '/api/v1/profiles/orgchart/',
            'beforeSend': function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', token);},
            'nodeContent': 'account_firstname'
        });

但这不起作用

【问题讨论】:

    标签: jquery ajax request http-headers orgchart


    【解决方案1】:

    为什么不使用 ajax 获取 json 数据源,然后通过 ajax 请求使用获取的数据源创建 orgchart。

    $.ajax({
      'url': '/api/v1/profiles/orgchart/',
      'beforeSend': function(xhr){xhr.setRequestHeader('X-CSRF-TOKEN', token);},
    })
    .done(function( data ) {
       $('#chart-container').orgchart({
            'data' : data
            'nodeContent': 'account_firstname'
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-22
      • 2015-06-20
      • 2018-03-30
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 2011-08-08
      • 2015-10-30
      相关资源
      最近更新 更多