javascript - 如何打印或获取从jquery发送到php文件Wordpress的数组

标签 javascript php jquery arrays wordpress

我想将 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/

相关文章:

php - PDO #1054 'where 子句中的未知列 'n'

JQuery UI 显示 ('slide' ,{direction : right}, 500) 不滑动,仅显示

javascript - 在随机的、不断变化的位置临时替换图像

javascript - 启动 jquery fadeToggle 隐藏

javascript - 无法显示选项、单选和数值输入组合的结果

javascript - ng-if 更改类别并 ng-click

php - 更新应用程序或数据库中的时间戳列?

javascript - 如何从位于 updatePanel 的 Gridview 中的 LinkBut​​ton 触发 Onclick 事件?

php - 将字符串与 [PHP] 之间的标签一起分解

javascript - JSON 数组数据返回 Undefined