Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9316969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:45:38+00:00 2026-06-19T02:45:38+00:00

I need to load $message1 and $message2 back into index.php when the corresponding anchors

  • 0

I need to load $message1 and $message2 back into index.php when the corresponding anchors are clicked, with ajax, so that the new values are displayed in index.php without the page resfreshing. this code functions as is, I just can’t figure out how to do this, could anybody help me figure out how? I’ve never written this type of script before and have gotten a little advice on how to do it but I’m still very confused.

this is my general.js file

$(".vote").click(function() {
var id = $(this).attr("id");
var name = $(this).attr("name");
var eData = $(this).attr("data-options");
var dataString = 'id='+ id + '&' + eData ;
var parent = $(this);

if(name=='up')
{
   $(this).fadeIn(200).html('');
   $.ajax({
      type: "POST",
      url: "up.php",
      data: dataString,
      cache: false,
      success: function(html){
         parent.html(html);
      }
   });
}
else
{
   $(this).fadeIn(200).html('');
   $.ajax({
      type: "POST",
      url: "down.php",
      data: dataString,
      cache: false,
      success: function(html){
         parent.html(html);
      }
   });
 }
 });

here is the html from my index.php

 <?php

 $sql = mysql_query("SELECT * FROM blogData ORDER BY id DESC");
 $sql2=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 0 ORDER BY mes_id DESC");
 $sql3=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 1 ORDER BY mes_id DESC");

 $count_variable = 0;

    while(($row = mysql_fetch_array($sql))AND($row2 = mysql_fetch_array($sql2))AND($row3 = mysql_fetch_array($sql3)) ){
        $id = $row['id'];
        $title = $row['title'];
        $content = $row['content'];
        $category = $row['category'];
        $podcast = $row['podcast'];
        $datetime = $row['datetime'];

        $message1=$row2['msg'];
        $mes_id1=$row2['mes_id'];
        $totalvotes1=$row2['totalvotes'];

        $message2=$row3['msg'];
        $mes_id2=$row3['mes_id'];
        $totalvotes2=$row3['totalvotes'];


    ?>

<table class="content">
 <tr>
 <td>


 <div id="main">
 <div id="left">
 <span class='up'><a href="" class="vote" name="up" data-options="key1=<?php echo $mes_id1;?>&key2=<?php echo $mes_id2;?>"><img src="up.png" alt="Down" /></a></span><br />
 <?php echo $totalvotes1; ?><br />
 </div>
 <div id="message">
 <?php echo $message1; ?>
 </div>
 <div class="clearfix"></div>
  </div>
 <div id="main">
 <div id="right">
 <br />
 <?php echo $totalvotes2; ?><br />
 <span class='down'><a href="" class="vote" name="down" data-options="key1=<?php echo $mes_id1;?>&key2=<?php echo $mes_id2;?>"><img src="down.png" alt="Down" /></a></span>
 </div>
 <div id="message">
 <?php echo $message2; ?>
 </div>
 <div class="clearfix"></div>
 </div>
 </td>
 </tr>
 </table>

 <?php
  }
  ?>

and here is my up.php file

 <?php

 session_start();
 include("config.php");

 $ip=$_SERVER['REMOTE_ADDR']; 

 $mes_id1 = $_POST['key1'];
 $mes_id2 = $_POST['key2'];
 $totalvotes1 = $_POST['key3'];

 $ip_sql=mysql_query("select ip_add from Voting_IP where mes_id_fk='$mes_id1' and ip_add='$ip'");
 $count=mysql_num_rows($ip_sql);

 $ip_sql2=mysql_query("select ip_add from Voting_IP where mes_id_fk='$mes_id2' and ip_add='$ip'");
 $count2=mysql_num_rows($ip_sql2);

 // if the user has already voted, execute script
 if($count==0 && $count2!=0)
 {
 $sql = "update Messages set totalvotes=totalvotes+1  where mes_id='$mes_id1'";
 mysql_query( $sql);

 $sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$mes_id1','$ip')";
 mysql_query( $sql_in);

 $sql = "update Messages set totalvotes=totalvotes-1  where mes_id='$mes_id2'";
 mysql_query( $sql);

 $sql_in = "DELETE FROM Voting_IP WHERE mes_id_fk='$mes_id2'";
 mysql_query( $sql_in);


 // if the user has not voted, execute script
 }
 else if($count==0 && count2==0)
 {
$sql = "update Messages set totalvotes=totalvotes+1  where mes_id='$mes_id1'";
 mysql_query( $sql);

 $sql_in = "insert into Voting_IP (mes_id_fk,ip_add) values ('$mes_id1','$ip')";
 mysql_query( $sql_in);

 }
 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:45:39+00:00Added an answer on June 19, 2026 at 2:45 am

    In your first Ajax request, for example, you have set the url to up.php

       $.ajax({
          type: "POST",
          url: "up.php",
          data: dataString,
          cache: false,
          success: function(html){
             parent.html(html);
          }
       });
    

    That means that you’ll be retrieving data from up.php. The way that an Ajax request works is that ANY data displayed on the php page, after it’s done loading, will be returned as a string to the page that sent the Ajax request.

    In your up.php page, you have not put any echo statements or any html code. Thus there is no data in your success function being returned. Which makes parent.html(html) redundant.

    You also cannot update variables on one php page from an Ajax request like you have specified. What you need to do is update the HTML data, or build the up.php page so that it returns a variable which you want to set to a Javascript variable in your success function….

    i.e.

    In up.php you must do the sql statement again, to retrieve the data that you want to change $message to and then echo that…

    More or less like this: (very generalized I know)

    $data = $_POST['ajaxRequestData'];
    //do something with the data to create a new SQL statement
    
    //do the sql statement and extract the value of $message that you're looking for
    //THEN****
    echo $message;
    

    Next in your Ajax success function…

    $.ajax({
          type: "POST",
          url: "up.php",
          data: dataString,
          cache: false,
          success: function(data){
             //here data will be equal to the value that you echoed in the up.php page.
             //do whatever you want to do with it... You will not have access to the php variable on this page with Javascript. 
             //Server sided languages like PHP do not talk directly with client sided languages like Javascript except with Ajax.
    
             updateMessage(data); //what I would do is create a function to send the variable to, to perform the necessary modifications to update your webpage.
          }
    });
    //Note that as soon as the success function ends, the returned data is no longer available to you 
    //so you must pass it to a function (or a global variable) to be able to use it.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to load data into my treestore. My ajax request give me XML
I need to Load RVM into a shell session as a function , so
I need to load a .xml file from a URL adress into an NSData
I need to load a file from an umounted TrueCrypt disk into memory. Is
I want to write a MobileSubstrate ( http://www.iphonedevwiki.net/index.php/MobileSubstrate ) addon that takes every HTTP
I have a package in R (ROCR) that I need to load in my
What I'm wanting to do is after I get the ajax request back that
I am still new at PHP/Javascript/Ajax and am having a very hard time (been
I write a chat module and i need to load previous messages to chat
I need to load a Model in a component to save the Data of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.