由于某些原因,我需要通过jquery加载一个PHP文件(在最后一点它将负责调用wordpress动态侧边栏但我无法在jquery中执行php)。我现在拥有的是:
$('#pa_kategoria-cenowa').after('<div class="product-variation-desc"><div id="5" class="box">CENA 5 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean semper egestas sodales. In commodo massa eget lectus eleifend, nec dictum sapien laoreet. </div><div id="10" class="box">CENA 10 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean semper egestas sodales. In commodo massa eget lectus eleifend, nec dictum sapien laoreet. </div><div id="15" class="box">CENA 15 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean semper egestas sodales. In commodo massa eget lectus eleifend, nec dictum sapien laoreet. </div></div>');
我的php文件名为: load-widgets.php
这就是为什么加载函数应该是这样的:
.load('load-widgets.php');
PHP文件的内容如下:
<div class="product-variation-desc"><div id="5" class="box">CENA 5 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean semper egestas sodales. In commodo massa eget lectus eleifend, nec dictum sapien laoreet. </div><div id="10" class="box">CENA 10 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean semper egestas sodales. In commodo massa eget lectus eleifend, nec dictum sapien laoreet. </div><div id="15" class="box">CENA 15 - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean semper egestas sodales. In commodo massa eget lectus eleifend, nec dictum sapien laoreet. </div></div>
但我不知道如何将它们组合在一起。我试过了:
$('#pa_kategoria-cenowa').after().load('load-widgets.php');
但它不起作用。如何实现?
答案 0 :(得分:1)
您现有的代码应该有效。检查控制台中的错误。如果这还没有解决,请尝试以下AJAX代码段。
$.get("load-widgets.php", function(data){ // Loads content into the 'data' variable.
$("#pa_kategoria-cenowa").after(data);
});