I have a form and what i need to do is to pass this form data to another page via jquery .post and below you will find the javascript
<script type="text/javascript">
$("form").submit(function(){
$(".application_container").append('<div class="preloading" style="padding-top:250px;"><img src="<?php echo base_url() . "assets/images/loading.gif";?>" alt="تحميل" /></div>').show();
var str = $("form").serialize();
var url = "<?php echo base_url() . "hawaa/confirm_applicant.html"; ?>";
$.post(url, function(str){
$(".application_container").append(str).show();
$(".preloading").remove();
});
return false;
});
</script>
the error that its request the another page but without sending the form submitted data to it, so it displays the validation error
You are using $.post()
incorrectly. You need to pass your data str
as the data parameter, like so:
$.post(url, str, function(data, status, jqXHR) {
// do stuff with response data here
});
You have to pass the str
variable as the second parameter to the $.post
call. The documentation states that:
So the correct way is:
<script type="text/javascript">
$("form").submit(function(){
$(".application_container").append('<div class="preloading" style="padding-top:250px;"><img src="<?php echo base_url() . "assets/images/loading.gif";?>" alt="تحميل" /></div>').show();
var str = $("form").serialize();
var url = "<?php echo base_url() . "hawaa/confirm_applicant.html"; ?>";
$.post(url, str, function(result){
$(".application_container").append(result).show();
$(".preloading").remove();
});
return false;
});
</script>