i have a code in jQuery which first validate the form using ajax and then resubmit the same form to another location but while resubmitting the submit button value not sending..
What will be the issue??
here’s the js code:
$.ajax({
'type': 'post',
'url': '/inc/do.php',
'data': $form.serialize(),
beforeSend: function(){
$form.find(':input').attr('disabled', true);
$form.find('.btn').addClass('bdsbld');
$form.find('.blkr').css('display', 'block');
},
error: function(){
Recaptcha.reload();
$form.find(':input').attr('disabled', false);
$form.find('.btn').removeClass('bdsbld');
$form.find('.blkr').css('display', 'none');
},
success: function(d){
$form.find(':input').removeAttr('disabled');
if(res=isJSON(d)){
if(!res.err && res.msg.toLowerCase()==='ok'){
if(($PRI_KEY=$form.find('input#PRIVATE_KEY')).length) $PRI_KEY.val(res.PRIVATE_KEY);
$form.append('<input type="hidden" id="PRIVATE_KEY" name="PRIVATE_KEY" value="'+res.PRIVATE_KEY+'" />');
$form.find('input#do').val('BOOK_AD');
$form.find('#reCaptchaO').remove();
form.submit();
}
else{
alert(res.msg);
Recaptcha.reload();
$form.find('.btn').removeClass('bdsbld');
$('#'+res.fld).delay(250).focus();
}
}
else
if(d!==''){
alert(d);
Recaptcha.reload();
$form.find('.btn').addClass('bdsbld');
}
$form.find('.blkr').css('display', 'none');
}
});
in this code, the line i.e.
form.submit();
is re-submitting the form but it is not including the submit button and its value but the submit button was included in the ajax request… why??
This is because the submit button is only included in the form submission traditionally when said submit button is clicked.
since you’re not submitting the form via the traditional
input="submit"button, no value is included.If you’re checking for this value on the server-side, it’s a static value that could be easily accomplished with a static hidden input, doesn’t seem to be a reason to fake a clicked submit button to retrieve a static value.