Помогите, я пытаюсь получить форму для отправки - стиль ajax.
По сути, я хотел бы иметь возможность "отправить" форму на другую страницу, не перенаправляя пользователя на вторую страницу. В идеале на странице форм должно отображаться какое-либо сообщение об успехе или неудаче.
Код ниже не работает. Я не уверен, в чем проблема.
Я протестировал свой process.php, разместив и перенаправив пользователя на страницу, и он работает безупречно. Любой совет, что я могу сделать, чтобы заставить это работать с ajax? (Я использую jquery)
<script>
$(function() { // wait for the DOM to be ready
$('#personal_email').submit(function() { // bind function to submit event of form
$.ajax({
type: $(this).attr('method'), // get type of request from 'method'
url: $(this).attr('action'), // get url of request from 'action'
data: $(this).serialize(), // serialize the form's data
success: function(responseText) {
// if everything goes well, update the div with the response
$('#result').html(responseText);
}
});
return false; // important: prevent the form from submitting
});
});
</script>
....
<form name="personal_email" id="personal_email" action="proccess.php" method="post">
<fieldset>
<input type="text" id="newsletteremail" name="newsletteremail" value="my email address" onfocus="if(this.value=='my email address')this.value=''"/>
<input type="submit" value="Subscribe" />
</p>
</fieldset>
</form>