나는 flipkart API 데이터를 얻으려고합니다. 당신은 내가 모두를 시도했지만 xhrfield와 헤더를 보낼 수 없습니다 ahve 의견을 볼 수 있듯이xhrfield와 함께 헤더를 보낼 수 없습니다
$.ajax({
type: 'GET',
url:'https://affiliate-api.flipkart.net/affiliate/search/json?query=iPhone+mobiles&resultCount=3',
crossDomain: true,
// dataType: 'JSONP',
/*xhrFields: {
withCredentials: true
},*/
// contentType: 'application/json; charset=utf-8',
beforeSend : function(xhr) {
xhr.withCredentials = true;
xhr.setRequestHeader('Fk-Affiliate-Id', 'myid');
xhr.setRequestHeader('Fk-Affiliate-Token', 'mytoken');
},
/* headers: {
'Access-Control-Allow-Origin':'*',
'Fk-Affiliate-Id': 'myid',
'Fk-Affiliate-Token': 'mytoken',
'Content-Type': 'application/x-www-form-urlencoded'
},*/
success: function(data){ ......
}
});
: 내가 xhrfield 와 heder을 보낼 수 없습니다 모르지만, 이런 식으로 여기 내 코드입니다. 내가 xhrfield 헤더를 보내 주겠다.
어떤 오류가 발생합니까? 둘 다 헤더를 보내는 올바른 방법입니다. 또한 myid와 mytoken이 변수가 아닌 객체가되어야하며 따옴표에 포함되지 않아야합니다. –
401 ,, 잘못된 헤더, Fk-Affiliate-Id 및 Fk-Affiliate-Token은 요청 헤더에서 전송되지 않습니다. –
JSONP 요청에서 헤더를 설정할 수 없습니다. – epascarello