Skip to content

CODExperiments

Doing it MY way!

  • Home
  • 2012
  • September
  • 10
  • Load data into table using JQuery and AJAX

Load data into table using JQuery and AJAX

Posted on September 10, 2012April 17, 2013 By Zoon 6 Comments on Load data into table using JQuery and AJAX
Programming

Time for a small JQuery post, which I’m sure some people will find useful. Now, first off, I don’t use JQuery on a regularly basic – so some things might be done quicker/better. I can only say that it works for me 🙂

The code presented will be using JQuery 1.7.2, but should also work with 1.8.x!

This example will load a JSON file once a button on the page is clicked! The request will be using AJAX. I’ve inserted some comments into the code, so it should be easy to understand.
[sourcecode language=”javascript”]
var globalgrid;
function loadgrid()
{
$.ajax({
type: ‘GET’,
dataType: ‘json’,
url: ‘ajaxdemo.json’,
success: function(griddata)
{
globalgrid = griddata.lines;

// remove all data – but the headers!
$("#gridtable").find("tr:gt(0)").remove();

if( globalgrid.length === 0)
{
$(‘#errormsg’).html(‘Sorry, <strong>no</strong> rows returned!’);
return;
}

for( var i=0; i < globalgrid.length; i++ )
{
var line = globalgrid[i];
// insert after last row! (yes! it *can* be done differently – but it works!)
$(‘#gridtable > tbody:last’).append(‘<tr><td>’+line.d1+'</td><td>’+line.d2+'</td><td>’+line.d3+'</td><td>’+line.d4+'</td></tr>’);
}
},
error: function(data, errorText)
{
$("#errormsg").html(errorText).show();
}
});
}
[/sourcecode]

The reason I save the data from the request in globalgrid is it is easier to debug later on (open the console in Chrome and type “globalgrid;” and you will know what I mean!)

I made a small example ready to run here. You are free to use the code 😉 If you find it usefull, drop me a line 😉

Post navigation

❮ Previous Post: Code Signing Certificate – or the lack thereof!
Next Post: NZB Completion Checker 1.2.2.0 released ❯

You may also like

Programming
Unblock Netflix
August 14, 2013
PHP
You want salt with that?
July 26, 2010
Programming
Time for some statistics
August 31, 2012
Programming
Glyph 3D
March 4, 2016

6 thoughts on “Load data into table using JQuery and AJAX”

  1. Christian Luneborg says:
    April 17, 2013 at 18:45

    You’re missing a demo on http://www.zoon.dk/2012/09/10/load-data-into-table-using-jquery-and-ajax/jquery_load_table_ajax_demo.html – Im looking for some help loading JSON data to table using Ajax.

  2. Zoon says:
    April 17, 2013 at 21:07

    Weird… don’t know why it’s missing… but you can find the demo here: http://www.zoon.dk/jquery_load_table_ajax_demo.html

  3. Dominika says:
    May 11, 2013 at 16:22

    I have to ask: How should json file look like for this example?? I’m new with ajax and json and it’ll be much of help for me to understand how it exactly works.

  4. Zoon says:
    May 11, 2013 at 23:09

    You can find the JSON used in this example here: http://www.zoon.dk/ajaxdemo.json

    Most newer, and some old, languages have native support for JSON. What programming language are you using?

  5. Dominika says:
    May 12, 2013 at 09:56

    Thank you!

  6. Javi says:
    August 21, 2013 at 10:52

    Thank you very much!
    works great!

Leave a Reply

You must be logged in to post a comment.

Downloads

Get it while it's HOT:
NZBcc 1.2.2.0

Downloads
might be ad supported. If so, click in top right corner to continue when the counter reaches 0.

Support NZBcc



Sign up to Dropbox using this link

Archives

  • March 2016
  • September 2014
  • July 2014
  • January 2014
  • August 2013
  • January 2013
  • December 2012
  • November 2012
  • September 2012
  • August 2012
  • June 2012
  • May 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • August 2011
  • July 2011
  • April 2011
  • January 2011
  • December 2010
  • November 2010
  • August 2010
  • July 2010
  • April 2010
  • March 2010
  • January 2009

Tag Cloud

AJAX Android Articles C# Download FMV Giganews HLSL HTML HTML5 Javascript jQuery MPEG Decoding MySQL Netflix NZB NZBcc PHP SQL Usenet Windows 7 XNA

Copyright © 2025 CODExperiments.

Theme: Oceanly News Dark by ScriptsTown