我想通过ajax将用户ID从我的表传递到modal,但只想到我得到的是"undefined"
。
当我替换var dataString = 'id=' + recipient;
时
与var dataString = 'id=' + 1;
它工作正常所以由于某种原因我无法获得点击变量的价值。我错过了什么?
PHP:
<?php
$query = mysql_query("select * from users");
$i=0;
while($fetch = mysql_fetch_array($query)):
echo '<tr>';
echo'<td> '.$fetch['user_id'].'</td>';
echo'<td> '.$fetch['user_name'].'</td>';
echo'<td> '.$fetch['user_email'].'</td>';
echo'<td> '.$fetch['user_imie'].'</td>';
echo'<td> '.$fetch['user_nazwisko'].'</td>';
echo'<td> '.$fetch['user_telefon'].'</td>';
echo'<td> '.$fetch['user_konto_akty'].'</td>';
echo'<td> '.$fetch['user_uprawnienia'].'</td>';
echo'<td>' .date("d.m.Y, H:i", $fetch['user_regdate']). '</td>';
echo'<td> <a class="btn btn-primary btn-sm" href="Kasuj_tab.php?user_id='.$fetch['user_id'].'">Usuń</a></td>';
?>
<td>
<a class="btn btn-small btn-primary" data-toggle="modal" data-target="#exampleModal_user" data-whatever1="<?php echo $fetch['user_id']; ?>">Edit</a></td>
<?php
echo '</tr>';
endwhile;
?>
的Ajax:
$('#exampleModal_user').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever1') // Extract info from data-* attributes
var modal = $(this);
var dataString = 'id=' + recipient;
$.ajax({
type: "GET",
url: "Modal_user.php",
data: dataString,
cache: false,
success: function (data) {
console.log(data);
modal.find('.ct').html(data);
},
error: function(err) {
console.log(err);
}
});
})
PHP:
<?php
include 'Panel_Logowanie/config.php';
db_connect();
$id = $_GET['id'];
echo"$id";
?>