I want to ajax post data which is dependent on my variables. I tried the following but no luck..
var datastring = "name:name,price:price,specialprice:specialprice,desc:desc,descs:descs,cat:cat,pictures:pictures,choiceimg:choiceimg,weight:weight,gtin:gtin,brand:brand,attid:attid";
if($("#color").val()) {
var color = $("#color").val();
datastring = datastring + ",color:color"
}
$.ajax({
type: 'POST',
data:{ datastring },
success: function() { },
error: function(){ },
url: 'insert.php',
cache:false
});
This posts as a string
datastring
name:name,price:price,specialprice:specialprice,desc:desc,descs:descs,cat:cat,pictures:pictures,choiceimg
:choiceimg,weight:weight,gtin:gtin,brand:brand,attid:attid
Any ideas / solutions ?