Mickey Patel Mickey Patel - 6 months ago 15
jQuery Question

How to convert a GET request to POST

I don't know if it is possible or not. I referred some site, but I didn't get exact answer.

I am using
<a href="xyz?id=4"> click </a>


When I send this request to server in the response page easily I can see "id=4" in address bar, obviously which is not secure, But in post request we cant see this.

So can we convert a get request to post or ant other way is there to hide this from address bar.

Thanks in advance.

anu anu
Answer
<a href="#" onclick="postForm()"> click </a>

Dynamically create a from and post it.

function postForm() {
var form = $('<form method="POST" action="xyz"></form>');
$(document.body).append(form);
form.append('<input type="hidden" name="id" value="4"/>');
form.submit();
}

As Racil suggested in comments, you can also do the following

<a href="#" id="postLink"> click </a>

and then

$('#postLink').click(function(e){
   e.preventDefault();
   //create form and post
});