为什么我的jQuery脚本无法在Word preSS触发? [英] Why is my jQuery script not triggering in Wordpress?
问题描述
我已经测试这是不使用任何CMS演示页上下面的脚本。
该脚本位于index.php文件和工作得很好。
I have tested the below script on a demo page which is not using any CMS. The script is located in the index.php file and works just fine.
<form method="get" action="">
<input id="label_search" type="text" value="" maxlength="40" name="inputText"/>
</form>
<script type="text/javascript">
var options = {
script:"includes/autosuggest.php?json=true&",
varname:"input",
minchars: 2,
delay: 200,
json:true,
shownoresults:false,
maxresults:15,
timeout: 5000
};
var as_json = new bsn.AutoSuggest('inputText', options);
</script>
现在我想使用相同的code在Word preSS模板文件。
但什么也没有发生。好像剧本完全不触发。
Now I want to use the same code in a Wordpress template file. But nothing is happening. Seems like the script is not triggering at all.
我使用用户友好的URL,并设置自定义永久链接/%类别%/%postname%。
也许这有什么话要说吗?
I'm using user friendly URL's and have set custom permalinks to /%category%/%postname%. Maybe that has something to say?
我知道bsn.AutoSuggest_2.1.3.js运行,因为警报('你好')的文件,测试在页面加载执行。
I know the bsn.AutoSuggest_2.1.3.js is running, because an "alert('hello')" test on the file is executed on page load.
有什么地方出错了?
这是我的WP code:
This is my WP code:
sl_startpage.php:
sl_startpage.php:
<?php
/*
Template Name: SL - Start page
*/
get_header(); ?>
<div id="myArea">
<?php
include_once('includes/storeLocator/sl_header.php');
?>
</div>
<?php
get_footer();
?>
这是(simplyfied)$ C $在sl_header.php C:
This is the (simplyfied) code in sl_header.php:
<div id="sl-header">
<form method="get" action="">
<input id="label_search" type="text" value="" maxlength="40" name="product_search"/>
</form>
</div>
<script type="text/javascript">
var options = {
script:"includes/autosuggest.php?json=true&",
varname:"input",
minchars: 2,
delay: 200,
json:true,
shownoresults:false,
maxresults:15,
timeout: 5000
};
var as_json = new bsn.AutoSuggest('product_search', options);
</script>
任何建议任何人吗?
Any suggestions anyone?
这是我使用的插件:
http://www.brandspankingnew.net/archive/2007/02/ajax_auto_suggest_v2.html
推荐答案
好吧!
约20小时的研究后,我发现在的由Ryan Pharis 博客。
当我怀疑,这是一个简单的解决方案。
Alright! After about 20 hours of research, I found the answer in a blog by Ryan Pharis. As I was suspecting, it was an easy solution.
字preSS采用用户友好网址」。
因此,我的路弄成这个样子:
的 http://www.mysite.com/includes/autosuggest.php?json=true&
Wordpress is using "user friendly URLS". Therefore my path ended up like this: http://www.mysite.com/includes/autosuggest.php?json=true&
真正的路径是这样的:
的http://www.mysite.com/wp-content/themes/my_theme/includes/autosuggest.php?json=true&
我的脚本不能设在外部。js脚本,因为我需要从Word preSS的URL。所以,我没有这样的:
My script cannot be located in an external .js script, because I need to get the URL from Wordpress. So I did this:
<?php $site_url = bloginfo('template_url'); ?>
<script type="text/javascript">
var options = {
script:"<?php echo $site_url; ?>includes/autosuggest.php?json=true&",
现在我的剧本的作品,我是一个快乐的人。
Now my script works and I'm a happy camper.
这篇关于为什么我的jQuery脚本无法在Word preSS触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!