1

I am implementing browser javascript code.

I have defined a link as follows

document.location.href ="/cssp_authorization?user_name="+ Ext.JSON.encode(user_name);

When a user clicks on the link the call gets directed to the /acspp_authorization page. However, I need to also pass a header information in this GET request. How can I do that?

Rocket Hazmat
  • 204,503
  • 39
  • 283
  • 323
Anna
  • 905
  • 1
  • 8
  • 13

1 Answers1

-1

I suggest switching to POST requests instead of GET and use setRequestHeader method of the standard XMLHTTPRequest:

xmlhttp.open("POST","cssp_authorization",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("My-Header","My-Value");
xmlhttp.send("user_name="+ Ext.JSON.encode(user_name));

You could use .ajax if jquery is your preferable option.

Max Malyk
  • 850
  • 5
  • 8
  • Why do you suggest a POST when a GET would do the job equally well? Also GET and POST have semantic value and are not interchangable. – Bart Sep 25 '13 at 20:09
  • There are many reasons, some explained here - http://stackoverflow.com/questions/3477333/what-is-the-difference-between-post-and-get – Max Malyk Sep 25 '13 at 20:12
  • If you read carefully you'll see why the POST request you're offering is considered invalid. – Bart Sep 25 '13 at 20:18
  • Can you please pin point the exact place you are referring to? – Max Malyk Sep 25 '13 at 20:27
  • Maybe it's better if I explain it. OP is not processing any form or data whatsoever. OP only wants to **get** a resource and send a custom header along with the request. Therefor POST is invalid. – Bart Sep 26 '13 at 09:12