Good Morning,
I am trying to get information that is json_encoded and use that to populate a tablesorter table. I am getting the following error: TypeError: data.sku is undefined. Here is my ajax code:
Code:
// to view and update inventory based on a sku range or a name
$('#getInfo').live('click', function() {
//clear table before search
$("#inventoryUpdate tbody tr").remove();
$.ajax({
type: "POST",
url: "getInventory.php",
datatype: "json",
data: ({skuStart: $("#startSkuRange").val(), skuEnd: $("#endSkuRange").val(), processDate: $("#processDate").val(),
source: $("#source").val()}),
success: function(data){
var sku = data.sku
console.log(data);
/*if(sku == null){
$("#inventoryUpdate").append('<tr><td>No Records Found</td></tr>');
}else{*/
for(var x=0;x<data.sku.length;x++)
{
$("#inventoryUpdate").append('<tr><td id="tableSKU">'+data.sku[x]+'</td><td id="tableISBN">'+data.isbn[x]+
'</td><td><input type="text" id="tableQuantity" value="'+data.quantity[x]+
'"/></td><td><input type="text" id="tableDefect" value="'+data.defect[x]+
'"/></td><td><input type="text" id="tableSource" value="'+data.source[x]+
'"/></td><td><input type="text" id="tableFeature" value="'+data.feature[x]+
'"/></td><td><input type="text id="tableLocation" value="'+data.location[x]+
'"/></td><td><input type="text" id="tableProcessDate" value="'+date.processDate[x]+
'"/></td><td><input type="text" id="tableBookType" value="'+data.booktype[x]+
'"/></td><td><input type="text" id="tableCreatedBy" value="'+data.created[x]+
'"/></td><td><input type="text" id="tableModifiedBy" value="'+data.modified[x]+
'"/></td></tr>');
}
$("#inventoryUpdate").trigger("update");
//} // end of else statement
} // end of success function
});// end of ajax call
}); // end of inventory update function
I know there is information there since it is show when I use Firebug and the console.log(data) line. Here is the data returned:
Code:
{"sku":["10123400","10123401","10123402","10123403","10123404","10123405","10123406","10123407","10123408","10123409","10123410","10123411","10123412","10123413","10123414","10123415","10123416","10123417","10123418"],"isbn":["9781416025405","9780072993288","9780534380311","9780495095538","9780781778107","9780205741786","9780673985255","9780618331505","9780321106766","9780495506218","9780321557537","9780534629915","9780312664817","9780198610298","9780323046343","9780323023108","9781439036402","9780132497992","9780538497817"]}
Does any one have an idea of what I am doing wrong? I am using the exact same code ( with a different table id) earlier in the page and it is working perfectly.