use*_*752 7 php jquery header http
我记得我去年使用jQuery ajax帖子,我可以通过输入简单地获取帖子数据$_POST['param'].今天我再次使用它来进行项目,所以我加载了最新的jQuery lib并使用了以下代码:
<script type="text/javascript">
$(document).on('submit', '.ajaxform', function(e){
e.preventDefault();
var datastring = $(this).serialize();
$.ajax({
type: "POST",
data: datastring,
contentType: "application/json; charset={CHARSET}",
dataType: "json",
beforeSend: function(){
console.log($(this).serialize());
},
success: function(data){
alert('yes');
},
error: function(errMsg){
alert('error');
}
});
});
</script>
<form action="" id="register" name="register" class="ajaxform" method="post" enctype="multipart/form-data">
<input type="text" name="username" value="" />
<input type="password" name="password" value="" />
<input type="hidden" name="action" value="register" />
<input type="hidden" name="{TOKENID}" value="{TOKEN}" />
<input type="submit" value="Register" />
</form>
Run Code Online (Sandbox Code Playgroud)
提交后,我无法通过键入获取输入字段值$_POST['username'].
我检查了检查元素,我注意到有些不同.
Request URL:http://project0/member.php
Request Method:POST
Status Code:200 OK
...
...
Content-Type:application/json; charset=UTF-8
...
...
Request payload:
username=asd&password=asd&action=register&29cd5e5ca1=73050db390872eb7c3fc564206b961c59a6363d6
Run Code Online (Sandbox Code Playgroud)
这就是为什么我不能通过简单输入获得POST数据$_POST['param']?如何返回POST数据而不是有效负载?
小智 11
除了:
contentType: "application/json; charset={CHARSET}"
Run Code Online (Sandbox Code Playgroud)
使用(内容类型的默认值):
contentType: "application/x-www-form-urlencoded; charset=UTF-8"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5993 次 |
| 最近记录: |