Running into a problem with some jQuery ajax. I've got three scenarios in which I'd send requests.
- Load a user's publications
- Move a user's publication categories up or down (i.e move books above articles)
- 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:
-
Array ( [action] => load [userid] => username )
This is correct -
Array ( [action] => load [userid] => Array ( [userid] => username [modifies] => c [action] => dn [id] => Book ) )
This is incorrect -
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.