I'm trying to send some data via ajax with jquery
var name = $(".name").attr("data-name");
var value = $(".value").attr("data-value");
$.ajax({
url: 'panel.php',
type: 'post',
data: {name: value}
}).done(function(){
alert("saved!");
});
So how can name and value be two variables. Now only value is a variable but what about name?
Cheers
try this:
var name = "data-name";
var value = "data-value";
var dataObj = {};
dataObj[name]=value;
$.ajax({
url: 'panel.php',
type: 'post',
data: dataObj,
}).done(function(){
alert("saved!");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With