4

I need to pass UserID as request header but I am not able to pass it with the request headerin the cross domain url.

Below is the screenshot for the Ajax Request in which I am getting the Accept-Control-Request-Header : UserID but when I pass it using the $.ajax() headers option; it not not shown in the Headers Tab of Firebug

enter image description here

I also tried the beforeSend option but no progress.

Below is the sample code which I have used,

headers: {'UserID': 12345 },
dataType: 'jsonp',
crossdomain: true,
beforeSend: function (request) {                
      request.withCredentials = true;
      request.setRequestHeader("UserID", "1");
      request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
      request.setRequestHeader("Access-Control-Allow-Origin", "*");
},

And I have referred all the below SO Urls,

  1. jQuery JSONP ajax, authentication header not being set
  2. Can I set headers in cross domain json requests?
  3. Modify HTTP Headers for a JSONP request

Is there a way to show the request headers in the Firebug Headers tab or it is the Server Side Security which blocks the request header.

1
  • I think, it seems not possible to send headers like this? Commented Feb 26, 2015 at 13:26

1 Answer 1

0

Finally, I got the solution.

There was no error at my end(client end). Actually the error was from server side, which was not allowing me to send headers. Allowing cross origin request parameters at server end the problem is solved.

Sign up to request clarification or add additional context in comments.

2 Comments

What needs to be changed at the server to allow them?
Server was provided by client, so I don't know what changes are made by him. But enable-cors.org/server.html might help you for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.