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 6696007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:17:25+00:00 2026-05-26T06:17:25+00:00

On the first page I have this function: <script> function update() { $(#notice_div).html(‘Loading..’); $.ajax({

  • 0

On the first page I have this function:

 <script>
function update() {
  $("#notice_div").html('Loading..'); 


  $.ajax({
    type: 'GET',
    dataType: 'json',
    data: latestid,
    url: '2includejson.php?lastid='+ latestid + '',
    timeout: 4000,
    success: function(data) {


      $("#cont_div").html(data);
      $("#cont_div").clone().prependTo($("#newdiv")); 
      $("#notice_div").html(''); 
      $("#cont_div").html('');
      window.setTimeout(update, 4000);

    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      $("#notice_div").html('Timeout contacting server..');
      window.setTimeout(update, 60000);
    }
});
}
$(document).ready(function() {
    update();

}); 
</script>

And some php.

The included file:

    <? 
     header("Content-Type: application/json", true);

    $la = $_GET['lastid'];  
    include ("../../setup.php");

    $jsonArray[] = array();

      $count = 1; // first message is the newest on load
      $get = $DB->query("SELECT * FROM board WHERE id>'$la' ORDER BY id DESC LIMIT 5", __FILE__, __LINE__);
    while ($msg = $DB->fetch_array($get))
    {   

  if($count == 1){ 
  $latestid = $msg['id']; // newest message - this I need to pass to the other page
  }
  $count++; 

    $jsonArray = "$msg[msg]";
    }
    echo json_encode($jsonArray);
    ?>

I’m just trying to learn how to use ajax and jquery.

As you see, I pass latestid as js variable through the URL
url: ‘2includejson.php?lastid=’+ latestid + ”,

I need to renew/post pack a newer value from the included page but I have no idea how to do so. Before using json I could just overwrite it with javascript, but now I don’t know… The newer value will then be posted again as latestid.

  • 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-05-26T06:17:25+00:00Added an answer on May 26, 2026 at 6:17 am

    You can declare the array without []:

    $jsonArray = array();
    

    Also you should then append the data to the array instead of making a string:

    $jsonArray[] = $msg['msg'];
    

    And in the end:

    $jsonArray['latestid'] = $latestid;
    

    Then in JavaScript, you should declare latestid:

    var latestid;
    

    And inside the ajax function, you should just pass the data as an object, and not twice like you’re doing now. And just replace latestid there, which has been returned in JSON format:

    ...
    data: {lastid: latestid},
    url: '2includejson.php',
    timeout: 4000,
    success: function(data) {
        latestid = data.latestid; // update latestid
        ...
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

BEFORE CHAOS I used to have this one... at the head part <script type=text/javascript>$(function()
I have an application where an HTML page first loads, then an applet with
I have a content script running on every page. It updates the html of
Currently I have two pages: The first page contains an input form, and the
I have a report where the first page has a certain top and bottom
I have two pages, on the first page after an event happens I change
I have a page that sites in a first level folder from my root
We have an issue on our page whereby the first time a button posts
I have an ASP.Net 2.0 page that contains two UpdatePanels. The first panel contains
Is it possible to get the value from the first page to the second

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.