2016-06-09 3 views
-3

У меня есть таблица с именами, когда я нажимаю имена, мне нужно открыть модальный текст и нанести имя, которое я нажал там. Как я могу это сделать? Заранее спасибоПолучить значение со страницы в модальном

report.php

кнопка:

<a href='#ReportModal' data-id='1' data-toggle='modal'>Open</a></td> 

модальный:

<div id="ReportModal" class="modal" role="dialog" data-backdrop="static" data-keyboard="false"> 
    <div class="modal-dialog"> 

    <!-- Modal content--> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h4 class="modal-title">asd</h4> 
     </div> 
     <div class="modal-body"> 
     //HOW TO PRINT HERE? 
     </div> 
     <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
    </div> 

    </div> 
</div> 

сценарий

<script> 
$(document).ready(function() { 
    $(document).on("click",".get-data"function(){ 
     var val = $(this).attr("data-id");  
     $.ajax({ 
      url: "../dist/scripts/report.userinfo.php", 
      type: "POST", 
      dataType: "HTML", 
      async: false, 
      success: function(data) { 
       $('.modal-body').html(data);   
      } 
     }); 

    }); 
}); 
</script> 

report.userinfo.php

<?php 
     include($_SERVER['DOCUMENT_ROOT']."/dist/config.php"); 
     $id = $_POST['id']; 
     $query = $db->query ("select Name from _reports where ID = '$id' ") or die($db->error()); 
     $rows= $query->fetch_array(); 
     echo $rows['Name']; 
    ?> 
+1

Пожалуйста, поделитесь код JS с нами, поэтому мы можем видеть, что вы уже пробовали, и как мы можем помочь вам. –

+0

@ Hr- вы не можете этого сделать. PHP является сервером и поэтому долго выполняется, когда вы нажимаете на самой странице. – DocRattie

+0

@DocRattie я добавил скрипт, пожалуйста, помогите) –

ответ

0

Вы почти все, теперь вам нужно только выполнить код, назначенный элементам с классом get-data. Чтобы достичь этого, вы можете добавить класс к своему якорю.

$(document).ready(function() { 
 

 
    $("#ReportModal").dialog(); 
 

 
    $(document).on("click", ".get-data", function() { 
 

 
    var val = $(this).attr("data-id"); 
 

 
    // for the sake of testing we assume your AJAX call works 
 
    // and then you can remove the following line and handle it 
 
    // in the success handler as shown in the comment below 
 
    $('.modal-body').html("You clicked: " + val); 
 

 
    /* 
 
    $.ajax({ 
 
     url: "../dist/scripts/report.userinfo.php", 
 
     type: "POST", 
 
     dataType: "HTML", 
 
     async: false, 
 
     success: function(data) { 
 
     $('.modal-body').html(data); 
 
     } 
 
    });*/ 
 

 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 

 
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
 

 
<a href='#ReportModal' data-id='1' data-toggle='modal' class="get-data">Open</a> 
 

 
<div id="ReportModal" class="modal" role="dialog" data-backdrop="static" data-keyboard="false"> 
 
    <div class="modal-dialog"> 
 

 
    <!-- Modal content--> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
 
     <h4 class="modal-title">asd</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     //HOW TO PRINT HERE? 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     </div> 
 
    </div> 
 

 
    </div> 
 
</div>

Смежные вопросы