Reputation: 99
I want to create a link that redirect to a page with POST method of data.
Is there any simple function to do this with Jquery?
Some thing like below code (without redirect to page)
<script language="javascript">
function DoPost(id){
$.post("http://www.jooyeshgar.dev/desktop/module.php?op=users&f=email", { fn: "read", time: id } ); //Your values here..
}
</script>
And
<a href='javascript:DoPost({$row_email['id']})'>
Thanks for your help
Upvotes: 1
Views: 1286
Reputation: 14665
It seems like you basically want to submit a form using an a
instead of a button (after you have populated it with some values).
The simplest (and pure javascript) solution is to have a form
(hidden, because it contains no visible elements) on your page (or create and append one dynamically):
<form id="myform" method="POST"
action="http://www.jooyeshgar.dev/desktop/module.php?op=users&f=email">
<input type="hidden" name="fn" value="read" />
<input type="hidden" name="time" value="" />
</form>
<a href="#" onclick="return !!DoPost(/*your string*/);">Submit</a>
And in javascript:
function DoPost(id){
var frm=document.getElementById('myform');
frm.time.value=id;
frm.submit();
}
Then let the browser do it's work :) as it is that behavior you seem to want.
That is the basics, you could translate it into jQuery based on the above concept.
Hope this helps!
Upvotes: 1
Reputation: 346
On success callback function of $.post you can replace url by using window.location.replace() method:
$.post("http://www.jooyeshgar.dev/desktop/module.php?op=users&f=email", { fn: "read", time: id }, function(){ window.location.replace('your url.'); } );
for ref: http://api.jquery.com/jquery.post/
Upvotes: 0
Reputation: 1091
If you are using JSP in your program do it as,
Have a form to get data from the user in JSP. And make the form method as "post"
Create a servlet with the name FormServlet and for the form action in jsp have it as action="FormServlet"
then from servlet use,
response.sendRedirect("nameofyourpage");
Hope this might help you.
Upvotes: 0