本文介绍了表单提交不刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能告诉我使用的 jQuery来显示成功的表单提交 *的的教程,而无需刷新页面的*。类似的事情发生在当消息被传递Gmail和黄色叠加显示您的邮件递送,然后褪色出局。我要显示的信息取决于表单提交的结果。
Can someone show me a tutorial of using jquery to display successful form submission *without refreshing the page*. Something like that happens on gmail when a message is delivered and the yellow overlay that shows that you message was delivered and then fade outs.I want the message to be displayed depending on the result of the form submission.
推荐答案
好吧......这样的事情......但我没有尝试...所以用它就像教程。您也可以使用JSON
Ok ... something like this ... but I didn't try it ... so use it just like tutorial.. You can also use json
记者:
function processForm() {
$.ajax( {
type: 'POST',
url: form_process.php,
data: 'user_name=' + encodeURIComponent(document.getElementById('user_name').value),
success: function(data) {
$('#message').html(data);
}
} );
}
HTML:
html:
<form action="" method="post" onsubmit="processForm();return false;">
<input type='text' name='user_name' id='user_name' value='' />
<input type='submit' name='submit' value='submit'/>
</form>
<div id='message'></div>
form_process.php
form_process.php
$user_name = $_POST['user_name'];
if(do something){
echo "login success";
else{
echo "login unsuccessful";
}
这篇关于表单提交不刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!