繁体   English   中英

一键式将数据插入Mysql并显示模式

[英]insert data into Mysql and show modal in one click codeigniter

我有下表:

http://i42.tinypic.com/sovfab.png

当我单击“加号”按钮时,需要将所有字段插入mysql中的新表中。 此外,我需要显示以下模式:

http://i39.tinypic.com/mrd63k.png

在简历中,我需要插入数据并在同一单击上显示模式。

我正在将MVC与codeigniter一起使用。

如果我独立进行操作,则可以插入数据并显示模式。

  • 要插入数据:

    我正在使用控制器,并且所有参数都使用URL插入。 示例: Localhost / Index.php / Controller?Parameter1&Parameter2&Parameter3

  • 显示模态:

我在用onclick="test()" javascript函数调用视图,并且该函数具有

function test(){ $('#myModal').modal('show'); }

或者更简单地说,我可以使用

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

我不确定我是否理解您的问题。 我认为您应该尝试ajax通话

$.post( "/Index.php/Controller?Parameter1&Parameter2&Parameter3/", function( data ) {
  $('#myModal').modal('show');
});

如果愿意,请尝试使用jQuery,它更容易,更简单

$(".plus").on("click",function(e){
    var postData ={};
    var tr = $(this).closest('tr');
    var td = tr.find('td');
    td.each(function(i,v){
        if(i< td.length-1){
            var key = $("#tab").find("th").eq(i).html();   
            postData[key]=$(this).html();
        }
    });
 //Now the parameters are ready send the ajax request
 $.post( "your_url", postData)
  .done(function( data ) {
     $('#myModal').modal('show');
  });
});

我假设您使用表格来获取字段,请使用:

    // This product objet to use in ajax
    var myData = $('#ID_FORM').serializeArray();        

    // This send to you page using POST
    $.ajax({
         url: 'test.php',
         data : myData,
         type: "post"
    });

    // Now, i recomend to use http://bootboxjs.com/
    // See docs, using this, look
    // Put data-attribute message in "A" to get it to use in modal box
    // use data-message
    // This plugin, need use bootstrap, is so easy

    $('a').on('click', function(){
        var msg = $(this).data('message');
        bootbox.alert(msg);
    });

我帮了忙

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM