[英]How do I include a $() element inside a .load();?
I'm trying to print some PHP content inside a simple Javascript call. 我试图在一个简单的Javascript调用中打印一些PHP内容。 The first one I got, but I have 2 vars to include, and one of them, must to be inside a .load().
我得到的第一个变量,但是要包含2个变量,其中一个变量必须位于.load()中。
I'll put the code bellow for a better understanding: 我将把代码放在下面以更好地理解:
<?php
$loadclass = 'filtersin';
$load_address = 'recebimento-filter';
$modal_ID = 'FilterModal';
?>
The JS calling (and what I'm trying to do): JS调用(以及我要执行的操作):
<script>
$(document).ready(function(){
var loadclass="<?php echo '.', $loadclass; ?>";
var load_address="<?php echo $load_address, '.php' ?>";
$(loadclass).load("dialogs/filter_group/",$(load_address) );
});
</script>
Change 更改
$(loadclass).load("dialogs/filter_group/",$(load_address) );
To 至
$('.' + loadclass).load("dialogs/filter_group/" + load_address );
loadclass
is now a class. loadclass
现在是一个类。 Notice the .
.
load_address
properly load_address
Description: Load data from the server and place the returned HTML into the matched element.
描述:从服务器加载数据并将返回的HTML放入匹配的元素。
So, if dialogs/filter_group/recebimento-filter
does not return HTML it won't work as expected. 因此,如果
dialogs/filter_group/recebimento-filter
不返回HTML,则它将无法按预期工作。
To fix this you can add a rewrite rule to .htaccess
要解决此问题,您可以向
.htaccess
添加重写规则
Replace: 更换:
var loadclass="<?php echo '.', $loadclass; ?>";
var load_address="<?php echo $load_address, '.php' ?>";
$(loadclass).load("dialogs/filter_group/",$(load_address) );
with 与
var loadclass="<?php echo '.' . $loadclass"; ?>";
var load_address="<?php echo $load_address . '.php'; ?>";
$(loadclass).load("dialogs/filter_group/" + load_address );
The string concatenatio sign is '.' 字符串连接符号为“。” in php and '+' in javascript, not ','
在php中,而在javascript中为“ +”,而不是“,”
Simpler: 更简单:
$("<?='.' . $loadclass ?>").load("dialogs/filter_group/<?= $load_address . '.php' ?>");
In both cases (with your initial values) results in: 在这两种情况下(使用您的初始值)都会导致:
$(".filtersin").load("dialogs/filter_group/recebimento-filter.php");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.