Reputation: 21
I have this code and i want send two value as you see i have ledit in data i want to send ledit2 with ledit
$('.ledit').click(function() {
var ledit = $(this).attr("id");
var ledit2 = $('.valu').val();
$.ajax({
url: 'edit.php',
data: 'ledit=' + ledit,
// here i want send ledit2
success: function(data) {
$('.edito').html('dddddddddd');
}
});
});
Upvotes: 2
Views: 686
Reputation: 123397
why two calls? Just do a single ajax call passing both the values
$.ajax({
url: 'edit.php',
data: 'ledit=' + ledit + "&ledit2=" + ledit2,
...
});
anyway unless you encode your values (e.g. with encodeURIComponent
) it's better to use an object, as suggested by @VisioN
Upvotes: 2
Reputation: 883
Have you tried to do it like this?
$.ajax({
url: 'edit.php',
data: '{ "ledit":' + ledit + ', "ledit2":' + ledit2 + '}',
success: function(data) {
$('.edito').html('dddddddddd');
}
});
Or much better:
$.ajax({
url: 'edit.php',
data: JSON.stringify({ ledit: ledit, ledit2: ledit2}),
success: function(data) {
$('.edito').html('dddddddddd');
}
});
Upvotes: 0
Reputation: 4192
You can use an object literal for the data
parameter:
data: { ledit: ledit, ledit2: ledit2 }
Or you can just use the &
operator in the URL:
data: 'ledit=' + ledit + '&ledit2=' + ledit2
Upvotes: 2
Reputation: 145408
You can set data
property as an object:
$('.ledit').click(function() {
var ledit = $(this).attr("id");
var ledit2 = $('.valu').val();
$.ajax({
url: 'edit.php',
data: {
ledit : ledit,
ledit2 : ledit2
},
success: function(data) {
$('.edito').html('dddddddddd');
}
});
});
Upvotes: 7