0

I am trying to get flipkart api data . like this but i am not able to send heder with xhrfield HERE IS MY CODE :

$.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){ ......
}
});

As you can see comment i ahve tried both but not able to send header with xhrfield . if i comment xhrfield header wil be send

Kakul Sarma
  • 303
  • 1
  • 4
  • 21

1 Answers1

0

You can not send a header with a JSONP requests since all it does is set a script tag to the page.

A JSONP requests consists of appending a script tag to the page. It adds a callback parameter to the URL which the script listens for when the script is executed. There is no way to add the header to a external script.

The site would need to support JSON request for CORs to send the header.

epascarello
  • 204,599
  • 20
  • 195
  • 236