gpt4 book ai didi

ajax - jquery表单提交

转载 作者:行者123 更新时间:2023-12-01 04:29:29 25 4
gpt4 key购买 nike

有人可以给我演示一下使用jquery在不刷新页面的情况下显示成功的表单提交的教程吗? 当邮件发送时,gmail 上会发生类似的情况,黄色叠加层显示您的邮件已发送,然后淡出。

最佳答案

使用jQuery + JSON组合是这样的:

test.php:

<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jsFile.js"></script>

<form action='_test.php' method='post' class='ajaxform'>
<input type='text' name='txt' value='Test Text'>
<input type='submit' value='submit'>
</form>

<div id='testDiv'></div>

_test.php:

<?php
// Code here to deal with your form submitted data.
$arr = array( 'testDiv' => 'Form is successfully submitted.' );
echo json_encode( $arr );
?>

jsFile.js:

jQuery(document).ready(function(){

jQuery('.ajaxform').submit( function() {

$.ajax({
url : $(this).attr('action'),
type : $(this).attr('method'),
dataType: 'json',
data : $(this).serialize(),
success : function( data ) {
for(var id in data) {
jQuery('#' + id).html( data[id] );
}
}
});

return false;
});

});



<小时/>

或:

您可以使用jQuery Form Plugin

关于ajax - jquery表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3748710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com