149
rated 0 times
[
150]
[
1]
/ answers: 1 / hits: 28155
/ 10 Years ago, wed, march 12, 2014, 12:00:00
I want to send key value pairs to my php page, but I need to set the key and value dynamically from data tags.
Here's the code I have until now:
function send(){
var attr = new Array();
var key = $('#add').attr('data-key');
var value = $('#add').attr('data-value');
attr.push({ key : value });
var data = {attributes: attr};
$.ajax({
url: ajax.php,
type: POST,
data: data,
success: function(result) {
alert(result)
}
});
}
This is not the actual code, it's just the basic functionality.
The problem is here:
attr.push({ key : value });
The 'key' is not taken as the variable I've set.
Can I please get some help? I'd really appreciate it. Thank you very much!
More From » jquery