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

  • Home
  • SEARCH
  • 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 7901947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:22:00+00:00 2026-06-03T09:22:00+00:00

I finally had success passing data through AJAX and returning it in JSON. However,

  • 0

I finally had success passing data through AJAX and returning it in JSON. However, now I don’t know how to display it on my page.

here is my JS:

$(function() {
    $( "#selectable" ).selectable({
        selected: updatefilters,
        unselected: updatefilters
    });   
    function updatefilters(ev, ui){
        // get the selected filters
        var $selected = $('#selectable').children('.ui-selected');
        // create a string that has each filter separated by a pipe ("|")
        var filters = $selected.map(function(){return this.id;}).get().join("\|");
        $.ajax({
            type: "POST",
            url: 'updatefilters',
            dataType: 'json', 
            data: { filters: filters },
            success: function(data){
                $('#board').replaceWith(data.content);
            }
        });
    }
});

after my model runs, it echos the following as discovered in firebug:

[{"thread_id":"226","owner_id":"1","subject":"trying to create a HUGE body for thread testi","body":"Firstly, I think 45 characters is perfect for the heading. \n\nHowever, once the body gets huge, I assume that the \"preview\" is going to get a bit out of hand if not truncated. I have truncated code in place...but it doesn't seem to be working.\n\nI'll have to keep testing to ensure we can get it shrunk down to a few hundred characters so as to not completely screw up the page format\n\nyadda yadda yadda...yadda yadda yadda...and more yadda yadda yadda...\n\nBabble Babble Babble Babble Babble \n\nBabble Babble Babble ","timestamp":"2012-05-02 15:29:19","replystamp":"2012-05-02 15:29:53","last_post_id":"1","slug":"226-trying-to-create-a-huge-body-for-thread-testi","replies_num":"1","views":"19"},{"thread_id":"219","owner_id":"3","subject":"testing icons","body":"hellow world","timestamp":"2012-05-01 11:37:08","replystamp":"2012-05-01 11:37:08","last_post_id":"3","slug":"219-testing-icons","replies_num":"0","views":"3"},{"thread_id":"212","owner_id":"1","subject":"This thread is based off entertainm","body":"Yay","timestamp":"2012-04-25 14:07:55","replystamp":"2012-04-25 14:07:55","last_post_id":"1","slug":"212-this-thread-is-based-off-entertainment","replies_num":"0","views":"4"}]

any advice on how to replace the div “board” with data from the returned JSON array would be incredibly helpful!

  • 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-03T09:22:01+00:00Added an answer on June 3, 2026 at 9:22 am

    Let’s say you want to display the data in a table with subject and body. You could write like this:

    success: function(data){
        var html = "<table>";
        for (i=0 ; i< data.length ; i++)
        {
            html += "<tr><td>" + data[i].subject + "</td><td>" + data[i].body + "</td></tr>";
        }
        html += "</table";
        $('#board').html(html);
    } 
    

    You get the idea. I also recommend looking into templating libraries mustache.js if you have time to investigate a nicer solution. That will let you separate your template from the data, and eliminate the ugly concatenation of HTML and data using Javascript. (Kind of a more advanced solution though, and you may want to just keep it simple.) Mustache.js engine allows you to write the above like this:

    var template = "{{#item}}<tr><td>{{subject}}</td><td>{{body}}</td></tr>{{/item}}";
    var html = "<table>" + mustache.render(template, data) + "</table>";
    $("#board").html(html);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Finally I had to recompile PHP with --enable-gd-jis-conv . However the text display is
I have had a lot of success creating graphs with Flot. However, I can
I have had a breakdown on my webhost. Now finally it is up again,
Had finally gotten all the bugs out of this and now they said Oh,
After searching a lot i did not get any answers and finally i had
I finally let windows nag me into upgrading from IE6 to 8. Now in
I've been using SO for a long time but finally had a question I
I had some messy code so I finally seperated it into headers and sources,
I have tried to many javascript plugins but finally had to post this question.
I had a problem recently with a php project that I finally realised was

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.