这是我的Javascript,用于获取输入框的值,
$('#edituserModal').on('show.bs.modal', function(e) {
var userid = $(e.relatedTarget).data('userid');
var u_id = document.getElementById('hdn_user_id').value = userid;
alert(userid);
});
我希望此值用于同一页面上的模态窗口中的SQL查询。 我在模态窗口中获取值但无法使用它。使用它的格式是什么。
答案 0 :(得分:1)
您可以使用ajax将js变量传递到php页面。
$('#edituserModal').on('show.bs.modal', function(e) {
var userid = $(e.relatedTarget).data('userid');
var u_id=document.getElementById('hdn_user_id').value=userid;
$.ajax({ //create an ajax request to load page.php
type: "GET",
url: "page.php",
data:"varabletophp="+u_id, //Here is the value you wish to pass in to php page
dataType: "html", //expect html to be returned
success: function(response){
alert(response);
}
});
});
不,你可以使用
将这个变量放到你的page.php(php页面)中$fromjs=$_GET['varabletophp'];
echo $fromjs;
答案 1 :(得分:0)
您可以使用隐藏输入并在此输入中设置用户ID值,以便发布表单
基于触发按钮改变模态内容: http://getbootstrap.com/javascript/#modals-related-target
var data = new FormData($('form#' + formId)[0]);
$.ajax({
type: "POST",
url: url,
data: data,
cache: false,
processData: false,
contentType: false,
beforeSend: function () {
},
success: function (response) {
},
error: function (response) {
}
});