Note that there are some explanatory texts on larger screens.

plurals
  1. POTable doesn't immediately show data obtained through ajax call
    primarykey
    data
    text
    <p>I'm getting json data from an ajax call as shown below:</p> <pre><code>/* * Get list of vendors and populate table */ function getVendors() { $ .ajax({ async : true, type : "GET", url : "/JavaTestService/rs/TestService/getMVendors?version=2", dataType : "json", success : function(json) { //add element to vendors array $.each(json.resultSet.merchandiseVendor, function(index,item){ nameLocal = item.name; numberLocal = item.number; vendorData[vendorDataCounter] = { name : nameLocal, number : numberLocal } vendorDataCounter++; }); initVendorTable(); }, error : function(xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); } </code></pre> <p>The initVendorTable() method is meant to populate a table with the data obtained from the above ajax call. initVendorTable() method shown below:</p> <pre><code>/* * Initialize the table containing the list of vendors */ function initVendorTable() { jQuery("#supplierTable").jqGrid({ datatype : "local", height : 250, colNames : [ 'Vendor Number', 'Vendor Name' ], colModel : [ { name : 'number', index : 'name', width : 200, sorttype : "int" }, { name : 'name', index : 'number', width : 200 } ], rowNum : 10, rowList : [ 10, 20, 30 ], sortname : 'number', viewrecords : true, sortorder : "desc", caption : "Suppliers" }); for(var i=0;i&lt;=vendorData.length;i++){ $("#supplierTable").jqGrid("addRowData",i+1,vendorData[i]); } alert(vendorData); } </code></pre> <p>I call the getVendors() method from a button click:</p> <pre><code>$(function() { $("#supplierSearchArea").dialog({ autoOpen : false, height : 400, width : 'auto', modal : true, title : 'Browse Suppliers' }); $("#supplierPopupButton").click(function(e) { $("#supplierSearchArea").dialog("open"); getVendors(); }); }); </code></pre> <p>The problem is that when I first click the button and the popup containing the table appears, the table is empty. This is because the array which I use to populate the table is empty.</p> <p>After stepping through the code, I've found that the initVendorTable() method gets called before the getVendors() method, even though I call the getVendors() method before the initVendorTable() method in the code. Is this an ajax quirk? Any suggestions on how I should work around this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload