duanqian3953 2013-09-09 12:36
浏览 56

单击按钮保存到数据库

I have a page with several models it.

If the user changes something in a texbox within the modal, is there a way it can save the changes on click without going to a new page?

Here is an example model:

<div id="myModal6" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                                    <h3 id="myModalLabel3">Homepage Testimonial</h3>
                                </div>
                                <div class="modal-body">

                               <h5><b>Testimonial: </b></h5>
              <textarea name="hometest" style="width: 500%" height:"150%";><?php echo $hometest ; ?>  </textarea>
              <br><br>

              <h5><b>Testimonial From:</b> </h5><input type="text" name="hometestfrom" value="<?php echo $hometestfrom ; ?>"><br>
                                </div>
                                <div class="modal-footer">
                                    <button class="btn red" data-dismiss="modal" aria-hidden="true">Cancel</button>
                                <a href='index.php'>    <button class="btn green">Save</button></a>
                                </div>
                            </div> 
  • 写回答

2条回答 默认 最新

  • duanli5662 2013-09-09 12:44
    关注

    Make a callable php function somewhere:

    function saveToDB() { 
      // save logic here, handle data from $_POST array  
    }
    

    In your modal window add a onclick="saveDataInDB()" to the Button

    <button class="btn green" onclick="saveDataInDB()">Save</button>

    then add a javascript that posts your required data to the php script

    <script>
    function saveDataInDB() {
        $.post('urlofphpscripthere',{'somedata': 'somethingfromyourform'},function(){ 
          // callback function, you could eg close your window if everything was saved successfully 
        });
    }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP