When i want to submit this form to the preferred URL using ajax function, but problem is that URL is going empty.I am using PHP codeigniter framework, hmvc .please anyone help me.There is form image.
<div class="actionElement">
<div class="form-group oh">
<div class="col-md-12">
<?php
echo form_open(base_url("demand/demand/sendmailto/".$demandid)," id='saveSerializeMedicalMulti'");
?>
<form action="javascript:void(0);" data-action="<?php echo base_url("demand/demand/sendmailto/".$demandid);?>" id="maillistdata" class="maillistdata" method="post">
<input type="text" value="<?php var_dump($multiId); ?>" name="multiid" id="multiid">
<input type="hidden" value="<?php echo $demandid; ?>" name="demandid" id="demandid" />
<div class="col-md-12 wrapper"><b>Company Name:<?php echo $this->demand_model->getCompanyName($result->NAME).'-'.$this->demand_model->getCountryById($result->COUNTRY); ?></b></div>
<div class="col-md-12">
<div class="col-md-6">Pre Auth Date:<?php echo $result->PRE_AUTH_DATE;?></div>
<div class="col-md-6">Lot No:<?php echo $result->LOT_NO; ?> </div>
</div>
<h5>Vacancy List   <span class="fa fa-list-ul"></span> </h5>
<table id="vacancyList" class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Category</th>
<th colspan="2">NOS</th>
<th colspan="2">Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<th>Male</th>
<th>Female</th>
<th>AED</th>
<th>NRs.</th>
</tr>
<tr>
<?php if ($demand!=''){
$cnt=0;
foreach ($demand as $r_child) {
?>
<td><?php echo ++$cnt; ?></td>
<td><?php echo $r_child->POST_NAME;?></td>
<td><?php echo $r_child->M_QUANTITY;?></td>
<td><?php echo $r_child->F_QUANTITY;?></td>
<td><?php echo $r_child->FROEIGN_CURR;?></td>
<td><?php echo $r_child->NEPALI_CURR;?></td>
</tr>
<?php }
}?>
</tbody>
</table>
<!-- <div class="oh">
<a href="<?php echo base_url("demand/demand/sendmailto/".$demandid); ?>" class="btn btn-info pull-right" id="multiSave">Save demand</a>
</div> -->
<!-- <button type="submit" id="sendmail" name="sendmail">Send Mail</button> -->
<a href="#" class="btn btn-info pull-right" id="sendmail" name="sendmail" >Send Mail</a>
<?php
echo form_close();
?>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
$(document).on("click", "#sendmail", function(){
//var url = $("#maillistdata").attr("action");
var url = $(form).attr("action");
var data = $('#maillistdata').serializeArray();
//alert($("#multiId").val());
alert(url);
data.push({name : 'multiId', value: $("#multiId").val() });
$.ajax({
type: 'post',
dataType: 'json',
url: url,
data: data,
success: function(response){
if(response.status==1){
$.gritter.add({
text: response.message
});
$("#multiId").val();
//alert($("#multiId").val());
bootbox.hideAll();
window.location = "<?php echo base_url().'demand/demand/sendmailto/'.$demandid; ?>"
return true;
}
else if(response.status==0){
var error=response.error.split("</p>");
for(var i=0;i<error.length;i++){
$.gritter.add({
text: error[i]
});
}
return false;
}
else{
$.gritter.add({
text: response.error
});
return false;
}
}
});
});
});
</script>
You should use data-action
instead of action
. The attribute added to form tag is data-action
. So you should use as below
var url = $(form).attr("data-action");
Also you should remove this line : echo form_open(base_url("demand/demand/sendmailto/".$demandid)," id='saveSerializeMedicalMulti'");
. Its creating duplicate form tag.
Also there is duplicate form tag in your code. You are using codeigniter form helper form_open() and also placing a form tag your self. Refer line 5 and 8 of your code.