Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Location
    Pennsylvania
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question AJAX help, PHP submit without refresh

    I have a different ajax function for each submit button but it does not work. It is on an auto-refresh of the div "content". Can anyone point out my mistakes?

    Code:
     <script type='text/javascript'>
     int likes, count, dlikes, nova;
     function doWorkl(){    
        httpObject = getHTTPObject();
        if (httpObject != null) {
            httpObject.open('POST', 'post.php?likes='
                +(likes+1),
                +'count='+count,
                +'dlikes='+dlikes,
                +'nova='+nova,true);
            httpObject.send(null); 
          }return:false;
    }
    
    function doWorkdl(){    
        httpObject = getHTTPObject();
        if (httpObject != null) {
            httpObject.open('POST', 'post.php?likes='
                +likes,
                +'count='+count,
                +'dlikes='+(dlikes+1),
                +'nova='+nova,true);
            httpObject.send(null); 
          }return:false;
    }
    function doWorkn(){    
        httpObject = getHTTPObject();
        if (httpObject != null) {
            httpObject.open('POST', 'post.php?likes='
                +likes,
                +'count='+count,
                +'dlikes='+dlikes,
                +'nova='+(nova+1),true);
            httpObject.send(null); 
          }return:false;
    }
    function doWorkr(){    
        httpObject = getHTTPObject();
        if (httpObject != null) {
            httpObject.open('POST', 'post.php?likes='
                +likes,
                +'count='+count,
                +'dlikes='+dlikes,
                +'nova='+nova,true);
            httpObject.send(null); 
          }return:false;
    }
     
     </script>
     
    
    
        
    <link rel='stylesheet' type='text/css' href='style.css'>
    
    <script language='javascript' type='text/javascript'>
    setInterval(function() {
    $('#content').load(location.href+' #content>*','');
    }, 5000);
    </script>
    </head><body>
    
    
    <div id=top>
      
    <center>
    <table><tr><td>";
    
    
    mysql_select_db("$db_database", $con);
    
    
     
    
    $result = mysql_query("$norm");
    $count=0;
    
    
    while($row = mysql_fetch_array($result))
    
    {
    
    echo "<script type='text/javascript'>";
    echo "likes=";
    echo $row['likes'];
    echo ";, count=";
    echo $row['count'];
    echo ";, dlikes=";
    echo $row['dlikes'];
    echo ";, nova=";
    echo $row['nova'];
    echo ";";
     
           
    echo "</script>";
    
    
    if(isset($_COOKIE['likesbn'.$row[count]]) || isset($_COOKIE['dlikesbn'.$row[count]])){
        $likesbn= "<span id=sub style='color:#6D6968!important;'>[Agree]</span><div style='display:none;'>";
        $likesbndiv="</div>";
         $dlikesbn= "<span id=sub style='color:#6D6968!important;'>[Disagree]</span><div style='display:none;'>";
        $dlikesbndiv="</div>";
    }  
    else{
    $likesbn= "";
    $likesbndiv="";
    $dlikesbn= "";
    $dlikesbndiv="";}
    
    
    
    if(isset($_COOKIE['novabn'.$row[count]])){
        $novabn= "<span id=sub style='color:#6D6968!important;'>[Villanova's Voice]</span><div style='display:none;'>";
        $novabndiv="</div>";
    }  
    else{$novabn= "";
        $novabndiv="";}
    
    if(isset($_COOKIE['reportbn'.$row[count]])){
        $reportbn= "<span id=sub style='color:#6D6968!important;'>[Report]</span><div style='display:none;'>"; 
        $reportbndiv="</div>";
    }  
    else{$reportbn= "";$reportbndiv="";}
    
    
    
    echo "<div id=content>";
    if($count<=$hn){ if($count<$ln || $count>$hn){echo "<div style='display:none;'>";}
    
    echo "<center>";
    echo "<table id='table'>";
      
    echo "<tr><td valign='center' colspan='5'><br>";
    
    echo "<p align=left style='font-size:12;'>";
    echo $row['post'];
    echo "</p>";
      
    echo "<br /></td></tr><tr><span style='font-size:12;'>";
    
    echo "<td valign='bottom'>";
    echo "<form name='myform1'>";
    echo $likesbn;
    echo "<input id=sub style='cursor: pointer;' type='submit' onclick='doWorkl();' value='[Agree]'>";
    echo $likesbndiv;
    echo $dlikesbn;
    echo "<input id=sub style='cursor: pointer;' type='submit' onclick='doWorkdl();' value='[Disagree]'>";
    echo $dlikesbndiv;
    echo $novabn;
    echo "<input id=sub style='cursor: pointer;' type='submit' onclick='doWorkn();' value='[Villanova&#039;s&nbsp;Voice]'>";
    echo $novabndiv;
    echo $reportbn;
    echo "<input id=sub style='color:red!important;cursor: pointer;' type='submit' onclick='doWorkr();' value='[Report]'>";
    echo $reportbndiv;
    echo "</form>";     
    echo "</td>";
     
    echo "</table>";
    Last edited by jquadr01; 03-11-2011 at 11:37 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
  •