아래 스크립트는 CMS를 사용하지 않는 데모 페이지에서 테스트했습니다. 스크립트는 index.php 파일에 있으며 잘 작동합니다.Wordpress에서 내 jQuery 스크립트가 실행되지 않는 이유는 무엇입니까?
<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>
이제 Wordpress 템플릿 파일에서 같은 코드를 사용하고 싶습니다. 하지만 아무 일도 일어나지 않습니다. 스크립트가 전혀 실행되지 않는 것 같습니다.
사용자 친화적 URL을 사용 중이며/% category %/% postname %에 맞춤 퍼 뮤 링크를 설정했습니다. 그럴 수도 있습니다.
페이지로드시 파일에 대한 "alert ('hello') 테스트가 실행되기 때문에 bsn.AutoSuggest_2.1.3.js가 실행 중임을 알고 있습니다.
무엇이 잘못 될 수 있습니까?
이 내 WP 코드 :
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();
?>
이것은 sl_header.php에서 (simplyfied) 코드 :
<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>
어떤 제안 누구?
이
플러그인 내가 사용된다 http://www.brandspankingnew.net/archive/2007/02/ajax_auto_suggest_v2.html
와우, 빠릅니다. 나는 그것이 내 자신의 실수임을 발견했다. "another/dir/sl_header.php"를 사용하고있었습니다. 올바른 경로를 설정하면 모든 것이 트리거됩니다. 이제 autosuggest.php 파일을 찾지 못하는 문제 만 있습니다. bsn.AutoSuggest ('product_search', 옵션)에서 알 수 있듯이 텍스트 상자의 올바른 이름을 사용하고 있습니다. 방화 광이 방금 404 찾을 수 없음을 제공합니다. – Steven
나는 다른 것을 가지고있다, 그것은 당신의 생성 된 페이지로부터 상대 URL로 해석 될 수있다. (위에서 편집을 참조) –
내 URL은 http : // localhost/mywebsite/store-locator이다. 파일에 대한 "실제"경로는 다음과 같습니다. http : //localhost/mywebsite/includes/autosuggest.php. 내가 Wordpress CMS에서 사용자 친화적 인 URL을 사용하고 있기 때문에 위의 제안이 효과가 없을 것이라고 생각합니다. 한 가지 이유는 'Hello World'를 표시하는 test.php를 만들어 루트 디렉토리에 배치하면 http : //localhost/mywebsite/test.php를 통해 액세스 할 수 없기 때문입니다. Wordpress는 "Nothing found"텍스트가있는 기본 템플릿 만 표시합니다. – Steven