Why doesn't my jQuery script run in Wordpress?

I tested the below script on a demo page that does not use CMS. The script is in the index.php file and it works 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>

Now I want to use the same code in the Wordpress template file. But nothing happens. It looks like the script is not running at all.

I use a convenient URL and set custom permalinks to /% category% /% postname%. Maybe there is something to say?

I know that bsn.AutoSuggest_2.1.3.js is running because the test "alert ('hello") in the file runs when the page loads.

What could be wrong?

This is my WP code:

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(); 
?>

This is the (simple) 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

0
2

! 20 http://www.mysite.com/includes/autosuggest.php?json=true&

REAL-: http://www.mysite.com/wp-content/themes/my_theme/includes/autosuggest.php?json=true&

script .js script, URL- Wordpress. :

<?php $site_url = bloginfo('template_url'); ?>

 <script type="text/javascript">
    var options = {
        script:"<?php echo $site_url; ?>includes/autosuggest.php?json=true&",

script , .

0
includes/autosuggest.php?json=true&

URL, ? , , , URL- autosuggest.php :

http://yourserver.com/includes/autosuggest.php

.. html () URL-:

http://yourserver.com/frontpage/
http://yourserver.com/categories/anotherpage/

, :

http://yourserver.com/frontpage/includes/autosuggest.php
http://yourserver.com/categories/anotherpage/includes/autosuggest.php

.. , , :

http://yourserver.com/includes/autosuggest.php

.. '/' URL- JSON , .

+1

Source: https://habr.com/ru/post/1708160/


All Articles