简体   繁体   English

jQuery load(),Bootstrap模式和PHP

[英]jQuery load(), Bootstrap modal, and PHP

I'm trying to load data in a Bootstrap modal depending on an ID passed to the modal through javascript. 我正在尝试通过Bootstrap模式加载数据,具体取决于通过javascript传递给模式的ID。 My modal link is: 我的模态链接是:

 echo "<a href=\\"#modal-edit\\" data-toggle=\\"modal\\" data-session-id=\\"".$mySessions->id."\\" title=\\"Edit Session\\"><i class=\\"fa fa-gear fa-2x text-primary\\"></i></a>&nbsp;\\n"; 

"sessionId" is a hidden field in the #modal-edit form that gets updated when an "Edit" button is clicked on one of the sessions listed in a table. “ sessionId”是#modal-edit表单中的隐藏字段,当在表中列出的会话之一上单击“编辑”按钮时,该字段将更新。 My script that sends sessionId to the hidden form field and attempts to load the php file is: 我的将sessionId发送到隐藏表单字段并尝试加载php文件的脚本是:

 $('#modal-edit').on('show.bs.modal', function(e) { var sessionId = $(e.relatedTarget).data('session-id'); $(e.currentTarget).find('input[name="sessionId"]').val(sessionId); $('#sessionLoadData').load('modal-edit-load.php?sessionId='.$sessionId); }); 

I have 我有

<div id="sessionLoadData"></div>

in my modal where I'd like to use modal-edit-load.php to lookup sessionId in a table of sessions, and return some html with the php variables echo'd in it at the same time the hidden field sessionId is updated. 在我的模态中,我想使用modal-edit-load.php在会话表中查找sessionId,并在更新隐藏字段sessionId的同时返回一些带有php变量的html。 I'm very new to java however, and feel like something just isn't quite there after following the recommended solution here: 但是,我对Java还是很陌生,在按照此处推荐的解决方案进行操作之后,感觉有些不完整:

SO Jquery load() and PHP variables SO Jquery load()和PHP变量

modal-edit-load.php?sessionId=1 works when I go to the page - it loads the form objects with the variables associated with sessionId 1. However, it does not work in the modal. 当我转到页面时,modal-edit-load.php?sessionId = 1起作用-它加载带有与sessionId 1相关联的变量的表单对象。但是,它在模式中不起作用。 The form objects do not appear when I click edit and the modal appears. 当我单击编辑并出现模式时,表单对象不会出现。

Am I using the javascript correctly to update the hidden field as well as loading the php file content to the modal? 我是否在正确使用javascript更新隐藏字段以及将php文件内容加载到模式中?

You're using the PHP $sessionId variable instead of the JavaScript sessionId variable that was pulled from the related element. 您使用的是PHP $sessionId变量,而不是从相关元素中提取的JavaScript sessionId变量。

$('#modal-edit').on('show.bs.modal', function(e) {
    var sessionId = $(e.relatedTarget).data('session-id');
    $(e.currentTarget).find('input[name="sessionId"]').val(sessionId);
    $('#sessionLoadData').load('modal-edit-load.php?sessionId=' + sessionId);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM