【问题标题】:An Array is no longer an array after an AJAX SendingAJAX 发送后数组不再是数组
【发布时间】:2012-02-17 23:01:07
【问题描述】:

我使用 jQuery UI 可排序插件,但未能成功使用 AJAX 发送“订单”变量(一个数组)。在 ajax 发送“订单”之后不再是一个数组。我想要一个只针对 ajax 发送的解决方案。

$("#list-cat").sortable({ 
    placeholder: 'highlight', 
    update: function() {  
    var order = $('#list-cat').sortable('serialize'); 

    $.ajax({
            dataType: 'json',               
            type: "POST",
            url: "my_url.php", 
            data: { action: "edit_cat_order", id_member: "<?php echo $id_member; ?>", id_page: "<?php echo $id_page; ?>", order: order },
            success: function(data){
                    if (data.a == true){    
                        $.colorbox({ html: data.b });                                       
                    }          
            },
            error:function (xhr, ajaxOptions, thrownError){
                        alert(xhr.responseText);
            }                       
        }); 

        }
 });

在“my_url.php”中,foreach 循环无法将 $_POST['order'] 识别为数组:“为 foreach() 提供的参数无效 ...”。我认为问题出在“数据”行,因为 $_POST['order'] 在我使用时是一个数组:

$.post("my_url.php", order);

【问题讨论】:

    标签: ajax jquery-ui jquery


    【解决方案1】:

    你可以试试

    $.post("imy_url.php", {order:order});
    

    编辑

    你可以使用$.makeArray

    $.ajax({
            dataType: 'json',               
            type: "POST",
            url: "my_url.php", 
            data: { action: "edit_cat_order", id_member: "<?php echo $id_member; ?>", id_page: "<?php echo $id_page; ?>", order: $.makeArray(order)},
            success: function(data){
                    if (data.a == true){    
                        $.colorbox({ html: data.b });                                       
                    }          
            },
    

    【讨论】:

    • 您好,我想有一个仅适用于 ajax 发送的解决方案(它已经适用于 $.post 发送)。
    猜你喜欢
    • 1970-01-01
    • 2018-01-18
    • 2020-08-08
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    相关资源
    最近更新 更多