Ajax调用控制台&x27;正确的数字,但php显示空值
我看过很多关于stackoverflow的相同问题,只是不明白为什么我的php显示null而不是数字 我有一个php:Ajax调用控制台&x27;正确的数字,但php显示空值,php,jquery,ajax,Php,Jquery,Ajax,我看过很多关于stackoverflow的相同问题,只是不明白为什么我的php显示null而不是数字 我有一个php: <?php $message .= "<br /><b>Beneficiaries:<b><br />\n\n"; $message .= "\n" . $_REQUEST['clickCount'] . "\n\n\n"; $benmax = 4; $var =json_encode($_GET['clickCount
<?php
$message .= "<br /><b>Beneficiaries:<b><br />\n\n";
$message .= "\n" . $_REQUEST['clickCount'] . "\n\n\n";
$benmax = 4;
$var =json_encode($_GET['clickCount']);
echo $var;
?>
然后,在我的html表单开始之前,在我的页面下方有一个in-ascript标记
<script type="text/javascript">
$(document).ready(function(){
console.log("ready");
var clickCount=1;
$('#showPartTwo').hide();
$('#yesExisting').click(function(){
console.log("clicked");
$('#showPartTwo').show();
});
$('#noExisting').click(function(){
console.log("no isclicked");
$('#showPartTwo').hide();
});
$('#addrow').click(function(){
console.log("inside");
clickCount=clickCount+1;
console.log(clickCount);
$('table').append('<tr><td><input class="form-control" type="text" name="benName'+clickCount+'" placeholder="Beneficiarys Name" /></td> <td><input class="form-control" type="text" name="benAddress'+clickCount+'" placeholder="Address" ></td> <td><input class="form-control" type="date" name="benDob'+clickCount+'" placeholder="Date of Birth" ></td> <td><input class="form-control" type="text" name="benRel'+clickCount+'" placeholder="Relationship" ></td> <td><input class="form-control" type="text" name="benPercentage'+clickCount+'" placeholder="Percentage of benefit" ></td></tr>');
});
$('#sendbutton').click(function(){
$.ajax({
url :'index2.php',
type:'POST',
data: {'clickCount': clickCount},
success: function(data){
console.log("success");
console.log(data);
}
});
});
});
</script>
$(文档).ready(函数(){
控制台日志(“就绪”);
var-clickCount=1;
$('#showPartTwo').hide();
$('yesisting')。单击(函数(){
控制台日志(“单击”);
$('#showPart2').show();
});
$(“#不存在”)。单击(函数(){
console.log(“未单击”);
$('#showPartTwo').hide();
});
$('#addrow')。单击(函数(){
控制台日志(“内部”);
clickCount=clickCount+1;
console.log(点击计数);
$(“表”)。追加(“”);
});
$(“#发送按钮”)。单击(函数(){
$.ajax({
url:'index2.php',
类型:'POST',
数据:{'clickCount':clickCount},
成功:功能(数据){
控制台日志(“成功”);
控制台日志(数据);
}
});
});
});
这是我的一些html表单
<form name="lifeform" action="index2.php?flag=1" method="post">
<h3 class="headingTitle">Beneficiaries</h3>
<table class="table table-striped border-collapse">
<thead>
<th>Name</th>
<th>Address</th>
<th>Date of Birth</th>
<th>Relationship</th>
<th>Percentage of benefit</th>
<th><input type="button" value="+" id="addrow"/></th>
</thead>
<tbody>
<tr class="benif">
<td><input class="form-control" type="text" name="benName1" placeholder="Beneficiary's Name" required></td>
<td><input class="form-control" type="text" name="benAddress1" placeholder="Address" required></td>
<td><input class="form-control" type="date" name="benDob1" placeholder="Date of Birth" required></td>
<td><input class="form-control" type="text" name="benRel1" placeholder="Relationship" required></td>
<td><input class="form-control" type="text" name="benPercentage1" placeholder="Percentage of benefit" required></td>
</tr>
</tbody>
</table>
<br/>
<div style="text-align: right; margin-bottom:2rem;">
<input class="btn btn-primary" type="submit" value="Send Application" id="sendbutton" name="sendbutton">
</div>
</form>
受益人
名称
住址
出生日期
关系
受益百分比
有人能告诉我为什么返回空值吗?订单错了吗??我说的不对吗?js中的调用是一种
POST
方法,您应该使用$\u POST在PHP中获得正确的值
诸如此类:
$var=json_encode($_POST['clickCount'])
我希望这能帮助您您通过邮寄发送数据,但通过
$\u GET
读取数据?