I was receiving the following error:
TypeError: data.isbn is undefined
I have since added in the data.isbn ==null
statement in the following code:
$.ajax({
type: "POST",
url: "getInventory.php",
datatype: "json",
data: ({skuStart: $("#startSkuRange").val(), skuEnd: $("#endSkuRange").val(),
processDate: $("#processDate").val(), source: $("#source").val()}),
success: function(data) {
console.log(data);
if (data.isbn == null) {
$("#inventoryUpdate").append('<tr><td>No Records Found</td></tr>');
} else {
for(var x=0; x<data.isbn.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 ajax call
This now returns No Records Found
, however, my console.log(data) is showing me that there are 19 isbn's. Can anyone see where the error lies? I am using identical code in another program and it works fine.
EDIT: Here is the PHP file that it gets the info from:
if(!empty($start) && !empty($end)){
$result = $conn->query("Select * from inventory where sku >= $start and sku <= $end");
} elseif (isset($start) && isset($end) && isset($source)){
$result = $conn->query("Select * from inventory where sku >= '$start' and sku <= '$end' and source_id = '$source'");
} elseif (isset($processDate)) {
$result = $conn->query("Select * from inventory where date_process = '$processDate'");
} else {
$result = $conn->query("Select * from inventory where sku >= '$start' and sku <= '$end' or source_id = '$source' or date_process = '$processDate'");
}
while($row = $result->fetch_assoc()) {
$skuArray[$x] = $row['sku'];
$isbnArray[$x] = $row['isbn13'];
$qtyArray[$x] = $row['quantity'];
$defectArray[$x] = $row['defect_id'];
$sourceArray[$x] = $row['source_id'];
$featureArray[$x] = $row['feature_id'];
$locationArray[$x] = $row['location_id'];
$processDateArray[$x] = $row['date_process'];
$bookTypeArray[$x] = $row['book_type_id'];
$createdByArray[$x] = $row['created_by'];
$modifiedByArray[$x] = $row['modified_by'];
$x++;
} // end of while loop
$results = array('sku' => $skuArray,
'isbn' =>$isbnArray,
'quantity' => $qtyArray,
'feature' => $featureArray,
'processDate' => $processDateArray,
'source' => $sourceArray,
'location' => $locationArray,
'created' => $createdByArray,
'modified' => $modifiedByArray,
'booktype' => $bookTypeArray,
'defect' => $defectArray,
);
$conn->close();
echo json_encode($results);
console.log(data) is:
{"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"]}
This is one string, but i edited it for easier reading and it does return the rest of the information asked for, but it is a long string and I did not add it for brevity.