On this page I am trying to create form by JQuery. I want to send data by method .post() using action="http://hebrew-transliteration.wz.cz/users/signup.php" but I am redirected instead. Where is the problem and how to successfully post it using JQuery AJAX?
https://krestanske-clanky.webnode.cz/vip/
When I click on button Send, I am redirected.
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if (jQuery) {
// jQuery is loaded
$form = $('<form id=current_sender action="http://hebrew-transliteration.wz.cz/users/signup.php" method=post></form>');
$form.append('<h2>Registrovat ke psaní komentářů</h2>');
$form.append('<label for="name1">Jméno či přezdívka: </label>');
$form.append('<input name=name1 type=input maxlength=15 size=10>');
$form.append('<label for=name2> Příjmení: </label>');
$form.append('<input name=name2 type=input maxlength=20 size=10>');
$form.append('<label for=email> Email:</label>');
$form.append('<input name=email type=input maxlength=40 size=10 value=@>');
$form.append(' <input type=submit value=Send>');
$('footer#footer').append($form);
} else {
alert("JQuery doesn't work");
}
});
$("#current_sender").submit(function(e) {
e.preventDefault(); // avoid to execute the submit
var form = $(this);
var url = form.attr('action');
alert(url);
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes form's elements.
success: function(data) {
alert(data); // show response
}
});
});
</script>