dqyq88053 2011-11-01 18:44
浏览 95
已采纳

多个jQuery Ajax请求变得混乱

Running into a problem with some jQuery ajax. I've got three scenarios in which I'd send requests.

  1. Load a user's publications
  2. Move a user's publication categories up or down (i.e move books above articles)
  3. Edit user's publications (i.e. change book to books for a category title)

After testing all the components individually and having them work as well as searching this site I'm pretty certain the issue is with the ajax requests.

The requests are called via button clicks. (i.e. <button onclick="edit_pubs('userid_modifies_action_id');">edit</button>)

The issue I'm getting is that on the page the data is getting sent to the arrays look like the following for each:

  1. Array ( [action] => load [userid] => username ) This is correct
  2. Array ( [action] => load [userid] => Array ( [userid] => username [modifies] => c [action] => dn [id] => Book ) ) This is incorrect
  3. Array ( [userid] => username [modifies] => c [action] => ed [id] => Book ) This is correct.

I cannot figure out why it nests the first array inside the third one.

Just a note, these arrays are the output of print_r ( $_POST ); directly before the die;.

I have the following setup for $.ajaxSetup:

$.ajaxSetup({
    url: "ajax_admin_load_pubs.php",
    global: false,
    type: "post"
});

Here are the ajax functions:

function modify_pubs(action) {
    var action_list = action.split('_');
    $.ajax({
        data : {'kuoid' : action_list[0], 'modifies' : action_list[1],
                'action' : action_list[2], 'id' : action_list[3]},
            dataType : "text",
            success : function(usr) {load_pubs(usr);}
    });
}

function load_pubs(usr) {
    $.ajax({
        // Tested data in either order, the array always appends itself to kuoid.
        data : {'action' : 'load', 'kuoid' : usr},
        dataType : "text",
        success : function(response) {  
            $('#pub-mod-list').html(response);
        }
    });
}

function edit_pubs(action) {
    var action_list = action.split('_');
    $.ajax({
        data : {'kuoid' : action_list[0], 'modifies' : action_list[1],
                'action' : action_list[2], 'id' : action_list[3]},
        dataType : "text",
        success : function(response) {
            $('#pub-mod-list').html(response);
        }
   });
}

As always, thanks for any help.

Edit: Since asking, I've found out the answer to the question. It was due to having a print_r($_POST) statement outside of an if statement like it should of been.

  • 写回答

1条回答 默认 最新

  • duanjuduo4573 2011-11-02 16:41
    关注

    It was due to having a print_r($_POST) statement outside of an if statement like it should of been. Thus when using jQuery.ajax the response was capturing that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器