Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a anchor tag which is redirecting to different Third party urls. I need to pass some parameters to those urls along with redirection. I need to pass parameters in POST request.

What I have tried:

JavaScript
function sendUsingPost(url,formFields){ 
    var urlP = url;
    var params = formFields.replace(",", "&");
    http.open("POST", urlP, true);
    
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    
    http.onreadystatechange = function() {//Call a function when the state changes.
      if(http.readyState == 4 && http.status == 200) {
		alert(http.responseText);
      }
    }
      http.send(params);
  }
Posted
v4
Comments
Kornfeld Eliyahu Peter 11-May-16 5:30am    
An anchor tag will use GET always...So how do you will to turn it into a POST?
Member 12226176 11-May-16 6:05am    
I am getting the response type(Get or post) from api. depending on that i will use anchor tag to redirect
Kornfeld Eliyahu Peter 11-May-16 6:15am    
You lost it...an anchor tag CAN NOT initiate a POST! You have to do some form manipulations (with hidden fields) or some JavaScript...no other way!
F-ES Sitecore 11-May-16 5:31am    
You can't instigate a POST from a link, you'll need a form on the page with hidden fields that contain your data and a click event on the link that submits the form.
Mohibur Rashid 11-May-16 5:35am    
if you ant to send in post, then, create onclick action and in onclick create form element and also add other element into the form, keep it hidden, no need to attach to body and finally 'created_form.submit()' will do the job

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900