【发布时间】:2014-11-22 01:01:58
【问题描述】:
我想使用切换按钮运行简码。如果开关是“ON”,我调用一个简码,如果它是“OFF”,我调用另一个。
作为一项测试,我尝试在单击带有 AJAX 的单个链接时调用短代码,它给了我这个:
文件“page-recherche.php”:
<a href="" id="clicklien">CLICK HERE</a>
<script>
$("#clicklien").click(function(e){
e.preventDefault();
$.ajax({
url: 'http://www.capitainebar.com/wp-content/themes/Capitaine-Bar/shortcode-recherche.php',
success: function (data) {
// this is executed when ajax call finished well
console.log('content of the executed page: ' + data);
$('body').append(data);
},
error: function (xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0) alert('got error: ' + status); // status 0 - when load is interrupted
}
});
});
</script
调用的文件是“shortcode-recherche.php”:
<?php echo do_shortcode( '[search-form id="1" showall="1"]' ); ?>
结果是一个致命错误。好像代码在“shortcode-recherche.php”而不是“page-recherche.php”中运行。
请注意,如果我将短代码直接写入我的页面,无需 AJAX 调用,它就可以正常工作。
你可以看到the result here
【问题讨论】:
-
你能发布你收到的错误吗?
-
致命错误:在第 1 行调用 /homepages/1/d543902707/htdocs/wp-content/themes/Capitaine-Bar/shortcode-recherche.php 中未定义的函数 do_shortcode()
标签: php jquery ajax wordpress shortcode