jQuery $.ajax post value is empty
jQuery $.ajax post value is empty
为什么我的代码发布值为空?我尝试每个回显键和值,但它显示"0 数组"
我的代码是这样的:
<script type="text/javascript">
$(document).ready(function() {
$("#btn_attend").click(function() {
$.ajax({
type: 'POST',
url: 'ajax.attend.php',
data: ' { user_attend: "<?php echo ($auth_user->is_attend()) ? "true" : "false"; ?>" }',
beforeSend: function() {
...
},
success: function() {
...
},
error: function() {
...
}
});
return false;
} else {
...
}
});
});
和开发人员工具显示帖子价值
开发人员工具
ajax.attend.php代码如下:
<?php
echo "POST=".strip_tags($_POST['user_attend']);
if(empty($_POST)==false)
{
...
}
else
{
echo "error:: empty post.";
}
?>
显示:
帖子=错误::空帖子。
由于要以参数键/值对的形式发送值,data
应该是对象而不是字符串,还需要将参数名称固定为userattend
data: { userattend: "<?php echo ($auth_user->is_attend()) ? true : false; ?>" }
我试试这段代码
foreach ($_POST as $key => $value){
echo "$key => $value";
if(is_array($value)){ //If $value is an array, print it as well!
printArray($value);
}
}
它显示这个
{_user_attend:_"true"_} =>
所以它没有发布价值。
我编辑这个,它有效!
data: { user_attend: "<?php echo ($auth_user->is_attend()) ? "true" : "false"; ?>" },
删除此" ' "
谢谢你们!
相关文章:
- Is onfling available for html, html5
- jQuery is not loaded
- reactRedux is not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Jquery - table.row(tr) is undefined
- contentWindow.document.body is null
- Tomcat websocket is not working
- $(.class).empty总是缺少一个元素
- Ember.TEMPLATES is empty (ember-cli-htmlbars)
- Angular if ng-repeat multi filter is empty
- jQuery $.ajax post value is empty
- req.session.passport is empty: req.user undefined
- Javascript - "this" is empty
- 从数组中选择随机项Remove It, Restart Once Array is Empty
- Angular $routeParams is empty
- evt.target.result is empty?
- Node.js express validator validate req.body is not empty
- Ajax responseText is empty
- simple Ajax (local): responseText is empty
- ng-bind-html is empty