How do I prevent the form from being redirected after submitting?
I searched the site and found various solutions, most of which suggested using
return false;
The problem is that I am using this piece of code to submit the form:
$(function() {
$("#snd").click(function() {
var dendar = "http://" + $("#inpt").val() + ":" + $("#pwd").val() + "secretsite.lol/something.xml";
$("#formen").attr("action", dendar);
$("#formen").submit();
alert(dendar);
return false;
});
});
A warning just to inform me that the form has been submitted.
Thanks guys!
+2
a source to share
4 answers
You must return false in the submit () call event handler, not the click handler.
$("#formen").attr("action", dendar); $("#formen").submit(
function() {
return false;
}
);
As others have noted, this will stop the form submission. What you want to do is collect the form data and submit it using an Ajax call.
$. post (url, {var1: value1, var2: value2 etc ...});
+4
a source to share