Results 1 to 2 of 2

Thread: AJAX sample problem

  1. #1

    Default AJAX sample problem

    I'm having a problem with an AJAX example I've thrown together. It works to update the DB, however the push back to the browser is not working. This is just a crude example where I'm trying to test.

    HTML file
    PHP Code:
    <html>
    <
    head>
    <
    script type="text/javascript">


    if(
    navigator.appName == "Microsoft Internet Explorer") {
      
    http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      
    http = new XMLHttpRequest();
    }

    function 
    addfav(linkid) {
      
    http.abort();
      
    http.open("POST""ajaxlinks.php?do=addfav&l=" linkidtrue);
      
    http.onreadystatechange=(My_AJAX_Reciever);
      
    http.send(null);
    }
    function 
    removefav(linkid) {
      
    http.abort();
      
    http.open("POST""ajaxlinks.php?do=removefav&l=" linkidtrue);
      
    http.onreadystatechange=(My_AJAX_Reciever);
      
    http.send(null);
    }
    function 
    My_AJAX_Reciever()
    {
        if (
    http.handler.readyState == 4)
        {
            
    document.getElementById('foo').innerHTML http.handler.responseText;
        }

    }

    </
    script>
    </
    head>
    <
    body>
    <
    form>
      <
    input value="Add Fav" type="button" onclick="addfav(4)" />
      <
    input value="Remove Fav" type="button" onclick="removefav(4)" />
    <
    div id="foo"></div>
    </
    form>

    </
    body>
    </
    html
    And the PHP file:

    PHP Code:
    <?php

    // ####################### SET PHP ENVIRONMENT ###########################
    error_reporting(E_ALL & ~E_NOTICE);

    // #################### DEFINE IMPORTANT CONSTANTS #######################
    define('THIS_SCRIPT''AJAX_LINKS');


    // ######################### REQUIRE BACK-END ############################
    require_once('./links_global.php');

    if (
    $_REQUEST['do'] == 'removefav')
    {
        
    $linkid $_REQUEST['l'];
        
    $db->query_write("DELETE FROM " TABLE_PREFIX "adv_links_favorites WHERE userid = " $vbulletin->userinfo['userid'] . " AND linkid = '$linkid'");

        echo 
    '1';
        
    }
    if  (
    $_REQUEST['do'] == 'addfav')
    {
        
    $linkid $_REQUEST['l'];
        
    $checkfav $db->query_first("SELECT linkid FROM " TABLE_PREFIX "adv_links_favorites WHERE userid = '" $vbulletin->userinfo['userid'] . "' AND linkid = '$linkid'");

        if (!
    $checkfav['linkid'])
        {
            
    $db->query_write("INSERT INTO " TABLE_PREFIX "adv_links_favorites (userid, linkid) VALUES ('" $vbulletin->userinfo['userid'] . "', '$linkid')");
            echo 
    '2';
            
        }
        
    }
        echo 
    '3';
    ?>
    The favorites table is updated, however the echo is not coming back to the browser. Any idea's on what I'm doing wrong?

  2. #2

    Default Re: AJAX sample problem

    Problem solved, just had to combine AddFav and RemoveFav into one function with a single call and everything works perfectly.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sample vBa Dynamics as Downloads manager
    By ncangler in forum "How Do I..." Questions
    Replies: 2
    Last Post: 10-16-2007, 05:16 PM
  2. Sample vBa Dynamics as Project or Support manager
    By ncangler in forum "How Do I..." Questions
    Replies: 2
    Last Post: 10-16-2007, 02:51 PM
  3. Any sample pages?
    By Kadi in forum "How Do I..." Questions
    Replies: 3
    Last Post: 05-15-2007, 07:32 AM
  4. VB Links Hangs on some URLs sample posted
    By Diggazz in forum Bugs From 2.0 RC1
    Replies: 6
    Last Post: 11-22-2006, 09:37 AM
  5. Sample Sites
    By greenhybrid in forum Troubleshooting / "How do I..." Questions
    Replies: 1
    Last Post: 05-03-2005, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •