weixin_33691817 2016-01-04 09:24 采纳率: 0%
浏览 15

使用Ajax提交表单

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 &nbsp <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>

enter image description here

  • 写回答

2条回答 默认 最新

  • weixin_33711641 2016-01-04 09:26
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!