i'm having problem getting the value of a variable into the modal which is supposed to be openning. i have tried using post but nothing changed. Both codes are in index.php.
我有问题将变量的值转换为应该打开的模态。我试过使用帖子但没有改变。两个代码都在index.php中。
This is the jquery script passing the value
这是传递值的jquery脚本
$(document).ready(function () {
$(".issue").click(function () {
var x = $(this).attr("id");
$.ajax({
url: "index.php",
type: "GET",
data: {data1: x,},
success: function () {
$("#modal2").modal('show');
}
});
});
});
And i tried echoing the id of class .issue but it doesn't works
我尝试回应类.issue的id,但它不起作用
<div class="modal fade" role = "dialog" id = "modal2" aria-labelledby = "myModalLabel" aria-hidden = "true">
<div class="dialog">
<div class="modal-content">
<div class="modal-body"><?php echo $_GET["data1"]; ?></div>
</div>
</div>
</div>
1 个解决方案
#1
0
You're missing the variable in the success method. It should be success:function(ajaxData){} So in all:
您在success方法中缺少变量。它应该是成功的:function(ajaxData){}所以:
var x = $(this).attr("id");
$.ajax({
url: "index.php",
type: "GET",
data: {data1: x,},
success: function (ajaxData) { // ajaxData is the return data from php
// add the data to the modal
$("#modal2 .modal-body").html(ajaxData);
$("#modal2").modal('show');
}
});
Are you sending the data server side to save it, or grab information from the database? If all you're trying to do is move the data to the modal, ajax isn't necessary.
您是要发送数据服务器端来保存它还是从数据库中获取信息?如果您要做的只是将数据移动到模态,则不需要ajax。
Part of me suspects you're not properly calling and passing the data to php, if you really do need ajax. The php you send the ajax data to should be a separate file, that receives it, processes it, and echos it back to the ajax success function. Then the ajax function puts the data in the modal and displays the modal.
我的一部分怀疑你没有正确调用并将数据传递给php,如果你真的需要ajax。你发送ajax数据的php应该是一个单独的文件,接收它,处理它,然后回传给ajax成功函数。然后ajax函数将数据放入模态中并显示模态。
Hope one of those thoughts points you in the right direction.
希望其中一个想法能指出你正确的方向。
#1
0
You're missing the variable in the success method. It should be success:function(ajaxData){} So in all:
您在success方法中缺少变量。它应该是成功的:function(ajaxData){}所以:
var x = $(this).attr("id");
$.ajax({
url: "index.php",
type: "GET",
data: {data1: x,},
success: function (ajaxData) { // ajaxData is the return data from php
// add the data to the modal
$("#modal2 .modal-body").html(ajaxData);
$("#modal2").modal('show');
}
});
Are you sending the data server side to save it, or grab information from the database? If all you're trying to do is move the data to the modal, ajax isn't necessary.
您是要发送数据服务器端来保存它还是从数据库中获取信息?如果您要做的只是将数据移动到模态,则不需要ajax。
Part of me suspects you're not properly calling and passing the data to php, if you really do need ajax. The php you send the ajax data to should be a separate file, that receives it, processes it, and echos it back to the ajax success function. Then the ajax function puts the data in the modal and displays the modal.
我的一部分怀疑你没有正确调用并将数据传递给php,如果你真的需要ajax。你发送ajax数据的php应该是一个单独的文件,接收它,处理它,然后回传给ajax成功函数。然后ajax函数将数据放入模态中并显示模态。
Hope one of those thoughts points you in the right direction.
希望其中一个想法能指出你正确的方向。