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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:05:14+00:00 2026-06-01T10:05:14+00:00

Currently all working with my jquery $.post actions, successful connections, query and json_encode return

  • 0

Currently all working with my jquery $.post actions, successful connections, query and json_encode return to my page. What I’m unable to do(and new to json) is how to display the returned values as a live feed? My current jquery js file is ‘jquery-1.7.2.min.js’ and my code is

    $(document).ready(function(){
      setInterval(function(){
      $.post('query.php', function(pendingReq){
      $('#div_id').html(pendingReq);
      }), 'json' });
    }, 5000

);

pendingReq is my returned data from the query and the current output looks like:
{"[0]":"FirstReq", "[1]":"SecondReq", ...."} based upon my mysql query build of the array

$res = array("[0]"=>var['1']...);

I am very new to using json, and don’t use a lot of javascript, but would like to have the returned data show up in a table, thank you.

My code below works, but for only one row of the mysql query, if two entries exist I get a “Uncaught SyntaxError: Unexpected token {” error in Firebug?? Still returning results as before:

    $res = array("req_name"=>$ew_display['req_name'], "date"=>$ew_display['req_dt']);
echo json_encode($res);



$(document).ready(function(){
            var table_template = "<table border=1 cellspacing=0 id='results'><tr><th>JTAR #</th><th>JTAR @</th></tr></table>";
            $("#testd").html(table_template);
    setInterval(function(){
        $.post("query.php", {track : 2}, function(pendingReq){
            var json = JSON.parse(pendingReq);
            var template = "<tr><td>{{req_name}}</td><td>{{date}}</td></tr>";
            var new_row = Mustache.render(template, json); 
            $("#results").append(new_row).fadeIn("slow");
        }), "json"
}, 5000);
  • 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-01T10:05:16+00:00Added an answer on June 1, 2026 at 10:05 am

    — EDIT —

    Since you’ve got an interval in there, the template can be constant:

    var table_template = "<table border=1 cellspacing=0 id='results_table'><tr><th>col1</th><th>col2</th></tr></table>";
    $("#div_id").html(table_template);
    var template = "<tr><td>{{[0]}}</td><td>{{[1]}}</td></tr>";
    

    Now for the interval, you can parse the result string and render each row:

    setInterval(function() {
        $.post("query.php", function(pendingReq) {
            var json = JSON.parse(pendingReq);
            var new_row = Mustache.render(template, json); 
            $("#results_table").append(new_row);
        });
    });
    

    — END EDIT —

    I’m a big fan of Mustache.js (https://github.com/janl/mustache.js), which allows you to separate your data (JSON) from your presentation (HTML table). I’m not a big fan of returning AJAX data from your server pre-formatted as HTML. You can use syntax like this (example only):

    var template = "<table>{{#item}}<tr><td>{{name}}</td><td>{{age}}</td><td>{{job}}</td></tr>{{/item}}</table>";
    var html = Mustache.render(template, pendingReq);
    $('#div_id').html(html);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working in an application where I need to find all occurrences
A database application that I'm currently working on, stores all sorts of settings in
I'm using jQuery to bind to all links on the page (I'm using the
I have a form which I'm using jQuery to post and working to handle
I'm currently working on a problem that basically involves processing all data in a
Created new scaffold Users that has fields name & description All working as suppose
I have been working on a template using almost all jquery/javascript. Mostly I am
Currently all our files are stored on a Windows network drive and with 15
Currently all our GUI components are written in MFC. Our build environment is: VC
Currently all of my script's settings are located in a PHP file which I

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.