PHP + AJAX

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CaNCeR
Forum Newbie
Posts: 3
Joined: Sat May 10, 2008 2:28 am

PHP + AJAX

Post by CaNCeR »

Hi everybody,

i have a problem with the implementation of php and ajax together. i found a menu script from internet which is written with Ajax and PHP. i wanted to implement this script on my local server. I downloaded all necessary files for this script. But it didnt work. This is the link of the script that i want to implement ; http://labs.activespotlight.net/jQuery/menu_demo.html

On the menu items there some links which starts with "fetch://" . In that site when i click to menu item, menu works. But when i click it on my local server, it is trying to open a page which has a link of starting with 'fetch://'.

I hope i could tell what my problem is. Can anybody help me about this subject. Because i need this script urgently. Thanx for your helps..
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: PHP + AJAX

Post by lafever »

Some code would probably help for a response.
CaNCeR
Forum Newbie
Posts: 3
Joined: Sat May 10, 2008 2:28 am

Re: PHP + AJAX

Post by CaNCeR »

The code of my page and the required files are ;

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
    <title>FastFind Menu</title>
    <style  type="text/css">
        body { font-family: verdana, arial, sans-serif; color: #535353; font-size: .62em;  }
                #launch
                { font-family: tahoma,sans-serif; }
                a#launch
                { text-decoration: none; color: #535353; }
                a#launch:HOVER
                { text-decoration: underline; color: #f90; }
        .ifM_header
        { cursor: Move; }
        #overview a { color: darkgreen; text-decoration: none; }
        #overview a:HOVER { color: #f90; }
</style>
    <link rel="stylesheet" type="text/css" href="ffDemo.css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="interface.js"></script>
    <script type="text/javascript" src="fastFind.js"></script>
    <script type="text/javascript">
    jQuery(function(){
            jQuery('div#ifM_wrapper_1').fastFind(
            {
                url:    'live-output.php',
                params: { 'current':1,'previous':false,'apiKey':'bd51b0648d268122996b9e68cfd86175' }
            });
            jQuery('.ifM_header a').click(function () {
                var el = jQuery(this).parents('div.ifM_box').get(0);
                jQuery(el).fastFindToggle(true);
                return false;
            });
            jQuery('#launch').click(function () {
                var el = jQuery(this).next('.ifM_box');
                jQuery(el).fastFindToggle();
                return false;
            }).html('[ Toggle Menu ]');
 
            // Make Draggable
            jQuery('div#debug').Draggable( { handle:'div.ifM_header' });
 
            // Hide the Box [ Safari Gives Error on Hide/Toggle/Css(display:none)/etc... ]
            var pivot = (jQuery.browser.safari)?false:true;
            jQuery('div#debug').fastFindToggle(null,pivot);
 
            // The follow code handles the legal disclaimer on this page 
            jQuery('div#showLegal a').click(function() { jQuery('div#legal').toggle(); });
            jQuery('div#legal').hide();
    });
    </script>
       
</head>
<body>
    <a href="#" id="launch">[ Loading... ]</a>
<div class="ifM_box" id="debug">
        <div class="ifM_header">
            <a href="#">x Close</a>
        </div>
        <div class="ifM_wrapper" id="ifM_wrapper_1">
<?php
/*
 * Sample Output Parser for jQuery PopUp Menu Plugin 
 *
 * License: http://labs.activespotlight.net/jQuery/license.html
 */
 
    // Defaults
    $current  = 1;
    //$previous = 1;
    $apiKey   = 'bd51b0648d268122996b9e68cfd86175';
    $who      = 'ActiveSpotLight';
    $depth    = 1;
 
    // Load Passed Data
    if(isset($_REQUEST['current']))
        $current = (int)$_REQUEST['current'];
    if(isset($_REQUEST['previous']))
        $previous = (int)$_REQUEST['previous'];
    if(isset($_REQUEST['apiKey']))
        $apiKey = $_REQUEST['apiKey'];
    if(isset($_REQUEST['client']))
        $who = $_REQUEST['client'];
 
    // Tile Range Check
    $min = 1; $max = 100;
    $current = checkRange($current,$min,$max);
 
    // Check API
    if(!checkAPI($apiKey,$who))
    {
        makeTile('ERROR',array('error'=>'Invalid API Key'));
        exit;
    }
 
    // Parse Request
    $status = 'OKAY';
    $auth = ",'apiKey':'{$apiKey}','client':'{$who}'";
    switch($current)
    {
        case 8:     // ISSUES: 2006
                        $d = array(
                                'title'         =>      'Issues 2006',
                                'sub'           =>      'Select an issue from the list below',
                                'options'       =>      array(
                                                'October 2006'          =>      "http://atlanta.activespotlight.net/Gallery_3,28",
                                                'September 2006'        =>      "http://atlanta.activespotlight.net/Gallery_3,21",
                                                'August 2006'           =>      "http://atlanta.activespotlight.net/Gallery_3,16",
                                                'July 2006'             =>  "http://atlanta.activespotlight.net/Gallery_3,15",
                        'June 2006'     =>  "http://atlanta.activespotlight.net/Gallery_3,11",
                        'May 2006'      =>  "http://atlanta.activespotlight.net/Gallery_3,10",
                        'April 2006'        =>  "http://atlanta.activespotlight.net/Gallery_3,6",
                        'March 2006'        =>  "http://atlanta.activespotlight.net/Gallery_3,7")
                        );
            $depth = 2;
            break;
        case 7:     // CATEGORY: AUTOMOTIVE
                       $d = array(
                                'title'         =>      'Automotive',
                                'sub'           =>      'Select a brand from the list below',
                                'options'       =>      array(
                                                'Cadillac'            =>      "http://atlanta.activespotlight.net/Advertisement_3,11,77",
                                                'Hummer'              =>      "http://atlanta.activespotlight.net/Advertisement_3,16,150",
                                                'Saab'                =>      "http://atlanta.activespotlight.net/Advertisement_3,6,47")
                        );
            $depth = 2;
            break;
        case 6:     // CATEGORY: APPAREL
                        $d = array(
                                'title'         =>      'Apparel',
                                'sub'           =>      'Select a brand from the list below',
                                'options'       =>      array(
                                                'Blue Genes'            =>      "http://atlanta.activespotlight.net/Advertisement_3,21,209",
                        'Intermix'      =>  "http://atlanta.activespotlight.net/Advertisement_3,7,31",
                        'Kate Spade'        =>  "http://atlanta.activespotlight.net/Advertisement_3,7,25")
                        );
            $depth = 2;
            break;
        case 5:     // MORE OPTIONS
                        $d = array(
                                'title'         =>      'More Options',
                                'sub'           =>      'Select an option from the list below',
                                'options'       =>      array(
                                                'Visit AtlantaMagazine.com'             =>      "http://www.atlantamagazine.com/",
                        'Visit ShopAtlantaMagazine.com'         =>      "http://www.shopatlantamagazine.com/",
                        'Subscribe to Atlanta Magazine'         =>      "#",
                        'Learn About Atlanta Magazine'          =>      "#",
                        'Learn About ActiveSpotLight'           =>      "http://www.activeSpotLight.com/")
                        );
            break;
        case 4:     // ISSUES
            $d = array(
                                'title'         =>      'Issues',
                                'sub'           =>      'Select a year from the list below',
                                'options'       =>      array(
                        '2006'      =>  "fetch://{'current':8,'previous':{$current}{$auth}}")
                        );
            break;
        case 3:     // CATEGORIES
            $d = array(
                                'title'         =>      'Categories',
                                'sub'           =>      'Select a category from the list below',
                                'options'       =>      array(
                        'Apparel'       =>  "fetch://{'current':6,'previous':{$current}{$auth}}",
                        'Automotive'        =>  "fetch://{'current':7,'previous':{$current}{$auth}}")
                        );
                        break;
        case 2:     // BRANDS
            $d = array(
                                'title'         =>      'Brands',
                                'sub'           =>      'Select a brand from the list below',
                                'options'       =>      array(
                                                'Atlantic Station'      =>      "http://atlanta.activespotlight.net/Advertisement_3,28,264",
                        'BloomingDales'     =>  "http://atlanta.activespotlight.net/Advertisement_3,28,278",
                        'Ferguson'      =>  "http://atlanta.activespotlight.net/Advertisement_3,28,267",
                        'Lenox Square'      =>  "http://atlanta.activespotlight.net/Advertisement_3,28,268",
                        'Georgia Premium Outlets'=> "http://atlanta.activespotlight.net/Advertisement_3,28,269",
                        'Oculus'        =>  "http://atlanta.activespotlight.net/Advertisement_3,28,270",
                        'Pile Family Nurseries' =>  "http://atlanta.activespotlight.net/Advertisement_3,28,273",
                        'Saab'          =>  "http://atlanta.activespotlight.net/Advertisement_3,28,272",
                        'Cadillac'      =>  "http://atlanta.activespotlight.net/Advertisement_3,28,265",
                        'SCAD'          =>  "http://atlanta.activespotlight.net/Advertisement_3,28,275",
                        'Top 10 Salons'     =>  "http://atlanta.activespotlight.net/Advertisement_3,28,274",
                        'Cayman Islands'    =>  "http://atlanta.activespotlight.net/Advertisement_3,28,289") 
                        );
            break;
        case 1:     // DEFAULT
        default:
            $d = array(
                'title'     =>  '',
                'sub'       =>  '',
                'options'   =>  array(
                        'Bilgisayar'        =>  "fetch://{'current':4,'previous':{$current}{$auth}}", 
                        'Ekonomi & Isletme'     =>  "fetch://{'current':2,'previous':{$current}{$auth}}",
                        'Elektrik & Elektronik' =>  "fetch://{'current':3,'previous':{$current}{$auth}}",
                        'Felsefe'       =>  "fetch://{'current':5,'previous':{$current}{$auth}}"),
            );
    }
 
    // Build Output 
    makeTile($status,$d);
 
    // Ensure Range Fix
    function checkRange($num,$min,$max)
    {
        if($num<$min) return $min;
        if($num>$max) return $max;
        return $num;
    }
 
    // check API
    function checkAPI($api,$who)
    {
        // Not Provided in Demo
        return true;
    }
 
    // make Tile
    function makeTile($stat,$data)
    {
    
?>
        <!--<div class="ifM_cats">
            <h1><? echo $data['title']; ?></h1>
            <p class="ifM_desc"><? echo $data['sub']; ?></p>
        </div> -->
        <div class="ifM_pager">
<?
        if(isset($data['options']) && count($data['options'])>8)
        {
?>
            <a href="#" rel="Up" title="Scroll Up" style="display:none"><img src="/resources/images/arrow_up.gif" alt="Scroll Up"/></a>
<?
        }   
?>
        </div>
        <div class="ifM_content">
<?
        if(isset($stat) && $stat=='ERROR')
        {
            $eMsg = 'An unknown error has occurred';
            if(isset($data['error'])) $eMsg = $data['error'];
            echo "<span class=\"ifM_error\">{$eMsg}</span>";
        }
        else
        {
            if(isset($data['options']) && is_array($data['options']))
            {
                foreach($data['options'] as $name=>$link)
                {
                    $class = (eregi('fetch://',$link))?' class="ifM_more"':'';
?>
            <a href="<? echo $link; ?>"  <? echo $class; ?>>&nbsp;<? echo $name; ?></a>
<?
                }
            }
        }
?>
        </div>
        <div class="ifM_pager">
<?
            if(isset($data['options']) && count($data['options'])>8)
            {
?>
            <a href="#" rel="Down" title="Scroll Down"><img src="/resources/images/arrow_dn.gif" alt="Scroll Down"/></a>
<?
        }
?>
        </div>
<?
        if($GLOBALS['previous'] > 0)
        {
?>
        <div class="ifM_back">
            <a href="fetch://{'previous':<? echo $GLOBALS['depth']; ?>}">&laquo; Back</a>       </div>
<?
        }
        if($GLOBALS['previous'] > 1)
        {
?>
        <div class="ifM_reset">
            <a href="#">&laquo; Home</a>
        </div>
<?
        }
    }
?> 
</div></div>  
</body>
</html>
Last edited by John Cartwright on Sat May 10, 2008 2:07 pm, edited 1 time in total.
Reason: Please use [code=php][/code] tags when posting php code
CaNCeR
Forum Newbie
Posts: 3
Joined: Sat May 10, 2008 2:28 am

Re: PHP + AJAX

Post by CaNCeR »

Here are the required files..
Attachments
fastFind.rar
Required Files
(21.13 KiB) Downloaded 17 times
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP + AJAX

Post by RobertGonzalez »

You know, that code is going to break all to hell if JS is turned off.

Do you have the right version of jQuery for that plugin? Can you copy their markup/JS to see if that exact same code works for you?
Post Reply