How to post two variables with jQuery AJAX? One variable work fine but two variables not working
function get() {
$('#age').hide();
$.post('jrecomment2.php',{ userID: form.userID.value },{ id_number: form.id_number.value }
function(output){
$('#age').html(output).slideDown(2000);
});
}
and the form:
<form name="form" dir="rtl">
<input type="text" name="userID">
<input type="text" name="id_number">
<input type="button" value="submit" style=" width: 120;" onClick="get();">
</form>
You need to use { userID: form.userID.value, id_number: form.id_number.value }.
$.post('jrecomment2.php',{ userID: form.userID.value, id_number: form.id_number.value }, function(output){ });
you can use this code
$.ajax({
type: "POST",
url: 'jrecomment2.php',
data: 'userID=' + form.userID.value+'&id_number='+form.id_number.value,
dataType: 'text',
async: false,
cache: false,
success: function (output) {
$('#age').html(output).slideDown(2000);
}
});
and post method
$.post('jrecomment2.php',{ userID: form.userID.value, id_number: form.id_number.value }, function(output)
{
$('#age').html(output).slideDown(2000);
}
);