Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Trouble building a dynamic data key


neophyte - 5:25 am on May 24, 2012 (gmt 0)


Hello All -

I want to dynamically build the parameters for the data key of an ajax call but I can't get it to won't work.

I've check my results with alert() and everything looks perfect but it still won't work.

Is it the way I'm quoting the different elements in the datalist?

Can someone see where I'm going wrong?

++++++++++++++++++++++++++++++++++++++++++++

function ajaxAction(vars)
{
var id = vars[0];
var table = vars[1];
var category = vars[2];
var action = vars[3];

var dataList = x = null;

x = 'action: ' + action + ', ';
x += 'rowid: ' + id + ', ';
x += 'table: ' + table + ', ';
x += 'category: ' + category;

dataList = '{ ' + x + ' }';

alert(dataList);
// the alert shown is correct:
//{ action: Delete, rowid: 20, table: tbl_attack_log, category: Guestbook }

$.ajax({
type: "POST",
url: "assets/ajax/backend_action.php",
data: dataList,
dataType: "json",
success: function(data) {
afterAction(data);
}
});
}


Thread source:: http://www.webmasterworld.com/javascript/4457217.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com