无法通过jQuery发送特定的标头

时间:2016-03-15 21:42:41

标签: jquery ajax api header

我的标题应如下所示:

GET /test/ HTTPS/1.1
Host: api.smartship.io
X-Smartship-Token: kXCVM0pCgB7QB5cp-DlnIo3TA77xZE_yqWqwnia1pGc
Content-Type: application/json

这必须是Ajax结果。

我正在尝试使用此脚本:

jQuery( document ).ready(function() {
    jQuery.ajax({
        type: 'GET',
        url: 'https://api.smartship.io/test',
        dataType: 'jsonp',
        contentType: 'application/json',
        beforeSend: function(xhr, settings) { 
            xhr.setRequestHeader('x-smartship-token','kXCVM0pCgB7QB5cp-DlnIo3TA77xZE_yqWqwnia1pGc');
        },
        success: function (json) { console.log(json) },
        error: function (json) { console.log(json) }
    });
});

但标题结果如下:

Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:es-ES,es;q=0.8
Access-Control-Request-Headers:accept, content-type, x-smartship-token
Access-Control-Request-Method:GET
Cache-Control:max-age=0
Connection:keep-alive
Host:api.smartship.io
Origin:http://new.prestoprint.ca
Referer:http://new.prestoprint.ca/

真的需要帮助:(

0 个答案:

没有答案