我想将jQuery中生成的数组发送到php文件。我陷入了困境。我试了好几种方法,但没有成功。我想回显/print_r php文件中的数组。专家们对我报以亲切的目光。我的代码如下:
js:
<script>
jQuery(document).ready(function($){
url = '<?php echo includes_url().'cs_cause.php'; ?>';
var allVals = [];
$('#deleteProduct').click(function(){
$('.delete-product:checked').each(function() {
allVals.push($(this).val());
});
$.post(url,{ array : allVals }, function(response,status){
alert( response+ ' ' + status);
});
})
})
</script>
php:
<?php
if($_POST['array'])
{
$r = $_POST["array"];
print_r($r);
}
?>
试试这样的东西,伙计。
<script>
jQuery(document).ready(function($){
url = "http://localhost/fundraise/wp-content/themes/aidreform/include/cs_cause.php";
var allVals = [];
$('#deleteProduct').click(function(){
$('.delete-product:checked').each(function() {
allVals.push($(this).val());
});
$.post(url,{ array : allVals }, function(response,status){
alert( response+ ' ' + status);
});
})
})
</script>
如果将此文件移动到服务器,请将url更改为
url = "/wp-content/themes/aidreform/include/cs_cause.php";