WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. spstieng
    Member
    Posted 5 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"/>
    </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 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.

    Anyone?

    This is the plugin I use:
    http://www.brandspankingnew.net/archive/2007/02/ajax_auto_suggest_v2.html

  2. spstieng
    Member
    Posted 5 years ago #

    Oh, one more thing.

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

  3. spstieng
    Member
    Posted 5 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. spstieng
    Member
    Posted 5 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