如何在jquery

时间:2017-01-07 10:19:53

标签: javascript jquery rest api

我在这里呼叫一个API,我得到了成功的回复,但他们返回总计数标题部分,我不知道如何取值。
见这里:
enter image description here

$.ajax({
  url: '//www.examples.com/api/get/',
  type: 'GET',
  contentType: 'application/json; charset=utf-8',
  success: function(result) {
    console.log(result);
  },
  error: function(errMsg) { 
    //console.log(errMsg); 
  }
});

2 个答案:

答案 0 :(得分:2)

尝试这个:成功回调中的request.getResponseHeader('x-Total-Count')

$.ajax({
  url: '//www.examples.com/api/get/',
  type: 'GET',
  contentType: 'application/json; charset=utf-8',
  success: function(data, textStatus, request){
        alert(request.getResponseHeader('x-Total-Count'));
   },
  error: function(errMsg) { 
    //console.log(errMsg); 
  }
});

答案 1 :(得分:0)

成功回调有3个参数,你可以点击here

$.ajax({
  url: '//www.examples.com/api/get/',
  type: 'GET',
  contentType: 'application/json; charset=utf-8',
  success: function (result, textStatus, xhr) {
    console.log(xhr.getResponseHeader('X-Total-Count'));
  },
  error: function(errMsg) { 
    //console.log(errMsg); 
  }
});