为什么我的代码帖子值为空? 我尝试使用foreach echo键和值,但它显示“0 Array”
我的代码是这样的:
<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.";
}
?>
显示:
POST = 错误::空帖。
答案 0 :(得分:2)
由于您希望将值作为参数键/值对发送, <p:panelGrid columns="1">
<p:panelGrid id="Input1">
<p:inputText size="40" id="searchValue" value="#{searchWindowBean.suggest}">
<p:ajax event="keyup" listener="#{searchWindowBean.changeOptions}" update="customeroptions" delay="300"
partialSubmit="true" process="@this" /> <!-- this update works-->
</p:inputText>
</p:panelGrid>
<p:panelGrid id="InputX">
<p:dataTable value="#{searchWindowBean.searchColumn.searchFields}" var="field">
<p:column>
<h:outputText value="#{field.displayName}" />
</p:column>
<p:column>
<p:inputText size="40" id="inputValue" value="#{field.value}">
<p:ajax event="keyup" listener="#{searchWindowBean.changeOptions}" update=":customeroptions" delay="300"
partialSubmit="true" process="@this" /> <!--this one doesn't-->
</p:inputText>
</p:column>
</p:dataTable>
</p:panelGrid>
<p:panelGrid>
<p:selectOneListbox value="#{searchWindowBean.selectItem}" id="customeroptions" styleClass="customeroptions"
scrollHeight="100">
<f:selectItems value="#{searchWindowBean.list}" />
<p:ajax disabled="#{!searchWindowBean.dependingFields}" partialSubmit="true"
update="contact_person" />
</p:selectOneListbox>
</p:panelGrid>
</p:panelGrid>
应该是对象而不是字符串,还需要将参数名称修改为data
userattend
答案 1 :(得分:0)
我试试这段代码
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"; ?>" },
谢谢你们!删除此&#34; &#39; &#34;