我想将 jQuery 生成的数组发送到 php 文件。我被困在这个问题上。我尝试了几种方法但没有运气。我想 echo/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";
关于javascript - 如何打印或获取从jquery发送到php文件Wordpress的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28825310/