weixin_33725722 2015-02-07 18:35 采纳率: 0%
浏览 23

Ajax-模态-传递变量

I know this has been asked a lot but after looking up for this for like 6 hours I can say I've tried everything that with my current knowledge (which isn't much) I can understand so I decided to come here and ask for help from the pros :).

This button is also inside korisnik.php

<button href="#myModal1" type="submit" role="button" data-toggle="modal" data-id="<?php print $row['kime']?>" class="open-myModal1"><span class="glyphicon glyphicon-edit"/></button>

This up top is a button that when clicked opens a modal and should pass a value to it, but it doesn't. After looking through a lot of posts on the net I found out easiest way is to send the variable back through AJAX so I used this:

This is located in bottom part of korisnik.php

$(document).on("click", ".open-myModal1", function () 
{
    var kime = $(this).data('id');
    $(".modal-body #kime").val( kime );
    $.post('korisnik.php', { 'kime': kime });
});

Using $kime = $_POST['kime']; print $kime; in korisnici.php doesn't show the value at all but using <input type="text" name="kime" id="kime" value=""/> does. Problem with the one that works is that I still don't have the value needed inside a variable and can't use it to make a query based on the sent value.

So my question is:

How to make this work with ajax so I can get the value with $_POST['kime']?

or

How can I save the value inside the input field inside a variable?

I hope I've been clear enough with my request. Either one of those works since I get what I want and that is a value saved inside a variable I can use for other things.

Thanks for any help.

EDIT: This is modal Code inside korisnik.php

            <div class="modal fade" id="myModal1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <center><h4 class="modal-title">EDIT KORISNIKA</h4></center>
                    </div><!-- end header -->
                    <hr/>
                    <div class="modal-body">
                        <!--<input type="text" name="kime" id="kime" value=""/>-->
                        <input type='text' name='kime' id='kime' value=''/>
                        <form class="form-horizontal" action='korisnik.php' method="post">
                        <?php
                        $kime = $_POST['kime'];
                        $query = $db->prepare("SELECT * FROM korisnik WHERE kime = :kime");             
                        $query-> execute(array(':kime' => $kime ));
                        $result = $query->fetch();
                        ?>
                            <table class="table table-striped"> 
                                <tr><th style="vertical-align:middle"><center>Korisničko Ime</center></th><td><input readonly class="form-control"  name="username" value="<?php print $result['kime'] ?>"id="username" type="text"></td></tr>
                                <tr><th style="vertical-align:middle"><center>Ime</center></th><td><input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)"  name="name" id="name" value="<?php print $result['ime'] ?>"  type="text"></td></tr>
                                <tr><th style="vertical-align:middle"><center>Prezime</center></th><td><input class="form-control" onkeydown="ime(this)" onkeyup="ime(this)" onblur="ime(this)" onclick="ime(this)" name="surname" id="surname" value="<?php print $result['prezime'] ?>" type="text"></td></tr>
                                <tr><th style="vertical-align:middle"><center>E-Mail</center></th><td><input class="form-control" name="email" id="email" onkeydown="emailk(this)" onkeyup="emailk(this)" onblur="emailk(this)" onclick="emailk(this)" value="<?php print $result['email'] ?>" type="email"></td></tr>
                                <tr><th style="vertical-align:middle"><center>Kredit</center></th><td><input class="form-control" name="kredit" id="kredit" onkeydown="alpha(this)" onkeyup="alpha(this)" onblur="alpha(this)" onclick="alpha(this)" value="<?php print $result['kredit'] ?>" type="number"></td></tr>
                            </table>
                    </div><!-- end body-->
                    <hr/>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-success pull-left" name="editk" value="Spremi Promjene" />
                        </form>         
                        <button class="btn btn-default pull-right" data-dismiss="modal" type="button">Odustani</button>
                    </div><!-- end footer -->
                </div><!-- end modal-content -->
            </div><!-- end modal-dialog -->
        </div><!-- end modal -->
  • 写回答

3条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 GEO下载数据的处理报错 :函数‘Meta’标签‘"data.frame"’找不到继承方法,如何解决?
      • ¥15 DLNM模型是否可以用二分类变量作为y变量
      • ¥15 android object box 一个实体多个表怎么写
      • ¥15 temux 启用docker 服务失败
      • ¥15 Flask 使用celery发送邮件出现‘目标计算机积极拒绝‘
      • ¥60 老人用的sd卡在手机里面不知道操作了什么,导致图片和视频变成了文件,取下sd卡连接电脑就是图中的样子,后缀改为.jpg才可以,需要用系统的画图软件才能打开,文件属性还是文件,有没有批量操作的解决办法
      • ¥15 超时跳出方法代码的返回值问题
      • ¥15 汇编语言程序设计设计,ascii码求数,再求数的BCD码
      • ¥30 Mask rcnn训练自己的数据集出现问题!
      • ¥20 研究人工智能时的几个问题