jQuery表单插件ajaxForm,ajaxSubmit使用详解
时间: 2023-12-02 12:05:01 浏览: 174
jQuery表单插件ajaxForm和ajaxSubmit都是用来实现表单提交的,其中ajaxForm适用于所有的表单,而ajaxSubmit只适用于表单中的input、select等元素,不能包含文件上传域。
ajaxForm的使用方法:
1.引入jQuery库和jquery.form.js插件文件
```
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
```
2.使用ajaxForm函数提交表单
```
$(document).ready(function() {
$('#form1').ajaxForm(function(data) {
alert(data);
});
});
```
其中,#form1是表单的ID,data是服务器端返回的数据。
ajaxSubmit的使用方法:
1.引入jQuery库和jquery.form.js插件文件
```
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
```
2.使用ajaxSubmit函数提交表单
```
$(document).ready(function() {
$('#form1').submit(function() {
$(this).ajaxSubmit({
success: function(data) {
alert(data);
}
});
return false;
});
});
```
其中,#form1是表单的ID,data是服务器端返回的数据。
ajaxSubmit还可以通过其他参数来设置表单提交的相关信息,如:
```
$(document).ready(function() {
$('#form1').submit(function() {
$(this).ajaxSubmit({
type: 'post', // 提交方式,get或post,默认为get
url: 'submit.php', // 提交的URL地址
data: { // 提交的数据,键值对形式
username: 'admin',
password: '123456'
},
dataType: 'json', // 服务器返回的数据类型,text、xml、json等
success: function(data) { // 提交成功后的回调函数
alert(data);
}
});
return false;
});
});
```
以上就是ajaxForm和ajaxSubmit的详细使用方法。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)