Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Accept头添加到jqueryajaxget(通过JSONP)请求_Jquery_Ajax_Get_Jsonp_Http Accept Header - Fatal编程技术网

将Accept头添加到jqueryajaxget(通过JSONP)请求

将Accept头添加到jqueryajaxget(通过JSONP)请求,jquery,ajax,get,jsonp,http-accept-header,Jquery,Ajax,Get,Jsonp,Http Accept Header,我试图向使用“jsonp”dataType的jQuery AJAX GET请求添加一个accept头,但由于某些原因,它不起作用。这是到目前为止我的代码 var e4json = JSON.stringify( { "thomas_smith106" : "Daniel244", "transaction_type" : "34", "trans

我试图向使用“jsonp”
dataType
的jQuery AJAX GET请求添加一个accept头,但由于某些原因,它不起作用。这是到目前为止我的代码

var e4json =  JSON.stringify( { 
                  "thomas_smith106"           : "Daniel244", 
                  "transaction_type"          : "34",
                  "transaction_tag"           : "902006933",
                  "authorization_num"         : "ET4653",
                  "amount"                    : "15.75"
              } ); 

$.ajax ({
    url: "https://api.demo.globalgatewaye4.firstdata.com",
    type: "GET",
    headers : {
        'accepts' : 'application/json'
    },
    data: e4json,
    dataType: "jsonp",
    success: function  (response) {
        alert('Successfuly called the e4 gateway api');
    }
});
我尝试了很多方法,但似乎没有任何效果。我查看了网站上的文档,但找不到任何好的例子

这是我得到的请求头。我需要accept头为“application/json”

Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie:_fd_session=d69310c5cd4a02a4700b5ba63f0d0c9b
Host:api.demo.globalgatewaye4.firstdata.com
Referer:http://localhost:8080/smart-two-site/customerinfo.html
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36

任何帮助都会很棒。谢谢

我想你应该这样设置:

      headers: {          
             Accept : "application/json; charset=utf-8",         
            "Content-Type": "application/json; charset=utf-8"   
      }   
用这个,

headers: {          
     Accept : "application/json; charset=utf-8",         
    "Content-Type": "application/json; charset=utf-8"   
} 

不幸的是,无法在JSONP请求上设置头。JSONP请求是通过向网站添加
标记来完成的,然后浏览器会像其他脚本一样加载该标记

当您说需要设置accepts标头时?当然,服务器就是通过您的请求接受内容的服务器,因此您需要设置内容类型。您试图实现的总体目标是什么?@Jordan“Content-Type”标题表示请求的类型(因此不用于GET)。服务器使用它将请求正文解码为有用的内容,或者在无法处理请求时拒绝请求。“Accept”标题是响应中接受的类型列表,可能按首选项进行加权。服务器使用此列表选择要发送的响应类型,或者在无法生成预期响应类型时拒绝请求。