[resolved] (Advanced) Not able to locate php file in jQuery (4 posts)

  1. Steven
    Posted 6 years ago #

    I've tested this script on a normal index.php file, which is not using any CMS. And it's working fine.

    `<form method="get" action="">
    <input id="label_search" type="text" value="" maxlength="40" name="inputText"/>

    <script type="text/javascript">
    var options = {
    minchars: 2,
    delay: 200,
    timeout: 5000
    var as_json = new bsn.AutoSuggest('inputText', options);

    Now I want to use the same code in a WordPress template.
    But nothing is happening. What could be wrong?

    Seems like the script is not triggering at all.
    I know the bsn.AutoSuggest_2.1.3.js is running, because an "alert('hello')" test on the file is executed on page load.


    This is the plugin I use:

  2. Steven
    Posted 6 years ago #

    Oh, one more thing.

    I've set permalinks to custom: /%category%/%postname%

  3. Steven
    Posted 6 years ago #

    To put the question in another way:

    How can a (jQuery) javascript locate the autosuggest.php which is located on mysite/includes/ directory?

    (When I am using user friendly URL's)

  4. Steven
    Posted 6 years ago #

    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.

    WordPress is using "user friendly URLS". Therefore my path ended up like this: http://www.mysite.com/includes/autosuggest.php?json=true&amp;

    The REAL path is this: http://www.mysite.com/wp-content/themes/my_theme/includes/autosuggest.php?json=true&amp;

    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&amp;",

    Now my script works and I'm a happy camper.

Topic Closed

This topic has been closed to new replies.

About this Topic