javascript - 无法使用 jQuery .submit() 获取 $_POST('input')
问题描述
我尝试使用 jQuery 上传表单submit()
并成功将页面重定向到 uploadAll.php,但是当我尝试使用获取输入数组$_POST['inputname']
时无法获取值。
我试图使用serialize()
,但我对应该放置 PHP 页面参考的位置感到困惑。
<form id="regForm" action="uploadAll.php" method="post" enctype="multipart/form-data">
//some inputs and a hidden input here
</form>
document.getElementById("regForm").submit(function() {
var inputValues = $(this).serialize();
$.ajax({
url: "uploadAll.php",
type: "POST",
data: inputValues
}).done(function(data) {
alert(data);
});
});
return false;
我可以不使用就提交serialize()
吗?看来我的序列化不起作用。任何帮助表示赞赏
解决方案
相信我,你的代码是错误的..
尝试使用此代码:
$("#regForm").on('submit', function(e) {
e.preventDefault();
var inputValues = $(this).serialize();
$.ajax({
url: "uploadAll.php",
type: "POST",
data: inputValues
}).done(function(data) {
alert(data);
});
});
推荐阅读
- css - 使用 CSS 识别定位器
- java - 是否可以使用仅在使用此枚举时定义的变量创建枚举?
- java - ProtoBuf Message Over Mqtt 订阅者问题
- html - Html 表格在 Internet Explorer 上不起作用
- node.js - Firebase 消息:应用程序/网络超时(发出请求时出错:超过 10000 毫秒的超时)
- c++ - C++20 中的 CTAD 和指定初始值设定项
- javascript - Vue.js,更改数组项的顺序并在 DOM 中进行更改
- php - 文件上传不工作,如果文件没有在 25-30 秒内上传
- python - 如何使用 3D 点、线和曲面数据绘制体积(.geo 文件)
- ruby - 在 ruby cmd 中将 scss 转换为 css 以编写 sass 代码