post方式提交数据
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>
我的第一个ajax
</title>
<link href="css/style.css" rel="stylesheet"/>
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
<div id="box" style="border:1px solid red;display: block;clear: both; width: 500px; height: 40px; margin:20px auto;">
</div>
<form id="form">
<div class="form-group">
<label>姓名:</label>
<input type="text" class="form-control " placeholder="姓名" name="user" >
</div>
<div class="form-group">
<label>价格:</label>
<input type="text" class="form-control" placeholder="价格" name="price" >
</div>
<div class="form-group">
<label>描述:</label>
<textarea class="form-control" rows="3" name="description"></textarea>
</div>
<div class="form-group">
<label>上传图片:</label>
<input type="file" name="img">
</div>
<center>
<button type="button" class="btn btn-default" name="submit">
提交
</button>
</center>
<div class="submit">
<span class="loading">正在提交...</span>
</div>
</form>
<script>
$(function() {
$('form button[type=button]').click(function() {
$.ajax({
type: "POST",
url: "formtest.php",
// 表单序列化
data: $('form').serialize(),
success: function(response, status, xhr) {
$('#box').html(response);
},
error: function(xhr, errorText, erroType) {
//alert('错误');
//alert(errorText+":"+erroType);
alert(xhr.status + ":" + xhr.statusText);
}
});
}); // $('form button[type=button]').click(function() {
// $.ajax({
// type: "POST",
// url: "formtest.php",
// //param() 方法用于在内部将元素值转换为序列化的字符串表示
// data:$.param({
// user:$('form input[name=user]').val(),
// price:$('form input[name=price]').val(),
// description:$('form textarea[name=description]').val()
// }),
// success: function(response, status, xhr) {
// $('#box').html(response);
// },
// error: function(xhr,errorText,erroType) {
// //alert('错误');
// //alert(errorText+":"+erroType);
// alert(xhr.status+":"+xhr.statusText);
// }
// });
// });
$(document).ajaxStart(function() {
$('.loading').show();
}).ajaxStop(function() {
$('.loading').hide();
});
})
</script>
</body>
</html>
formtest.php
<?php
echo $_POST['user']."-".$_POST['price']."-".$_POST['description'];
?>
最新文章
- 处理session跨域几种的方案
- Maven多环境打包
- 特殊字符(包含emoji)的梳理
- WPF自定义控件与样式(11)-等待/忙/正在加载状态-控件实现
- js——单选框radio
- jQuery选择器介绍:基本选择器、层次选择器、过滤选择器、表单选择器
- 【转】HTTP HEAD
- wpa_supplicant 连接成功后,如何配置wlan0与br0 协调上网
- SuperSlidev2.1 轮播图片和无缝滚动
- 批处理:遍历输出指定后缀格式的文件名.bat
- Linux——搭建PHP开发环境第四步:composer
- php发送post请求的三种方法示例
- hdu 4751 Divide Groups(dfs染色 或 2-sat)
- 整理Linux查看系统日志的一些经常使用命令
- 如何在IIS8.5上面部署php
- 挂接命令(mount) 【转】
- 从头编写 asp.net core 2.0 web api 基础框架 (1)
- 固定底部导航菜单-续集(BottomMenu-移动端V3.0)
- 细说MVC中仓储模式的应用
- python_sort(key=) 的使用
热门文章
- React Native(十三)&mdash;&mdash;ios键盘挡住textInput
- 《Mysql 入门很简单》(读后感②)
- .Net学习心得
- .NET批量数据入库
- JSON调试找不到 net.sf.ezmorph.Morpher
- MyEclipse中自定义maven命令(添加maven 命令)
- Find–atime –ctime –mtime的用法与区别总结
- 游戏服务器学习笔记 5———— twisted Perspective Broker 透明代理
- SharpGL学习笔记(二) 模型变换(几何变换)
- Visual Studio 2012创建SQL Server Database Project提示失败解决方法