i would appreciate any help with this issue i am making an ajax call fro. welcome.php file and its failing and i cant figure out the error.
ajax call:
//on clicking search Comp button
$("#searchBtn2").on('click',function() {
$.ajax({
url:"welcome-ajax.php",
type:"POST",
dataType:"json",
data:{
GetPipelines: "GetPipelines",
PCid :"JS-59",
}
}).done(function(Result){
if (Result == "200" || Result == 200) {
console.log(Result);
} else {
console.log(Result);
document.getElementById("addBarcode").value="Result[1]";
}
}).fail(function(xhr, textStatus, errorThrown) {
var error = textStatus;
var details = errorThrown;
//700 is a Database connection error
if (xhr.status == 700) {
error = "Could not connect to the Databse";
details = "The database is missing - OR - the server is refusing to connect/is down.";
// 701 is a query execution error
} else if (xhr.status == 701) {
error = "Could not find the specified table in the databse.";
details = "The table might have been deleted or moved to somewhere else.";
}
var subStr = xhr.responseText.match(":(.*).");
var div = document.createElement('div');
var response = div.innerText;
msg = " Oh snap! - an error occured while adding the device. You can find the details in the <a href="log.php?Status=" + xhr.status + "&StatusText=" + xhr.statusText + "&Response=" + response + "&Error=" + error + "&Detail=" + details + "" target="_blank" rel="noopener noreferrer">log</a>.";
console.log("Status=" + xhr.status + "&StatusText=" + xhr.statusText + "&Response=" + response + "&Error=" + error + "&Detail=" + details);
});
});
ajax code:
if (isset($_POST[‘GetPipelines’])) {
$PCid = $_POST['PCid'];
$Query = "SELECT * FROM db_runtimes.master_pl_time_actual_avg where System Like '%JS-59%' ;"
$AllRecords = array();
if (!$Result = mysqli_query($InventoryCon, $Query)) {
header('HTTP/1.1 701 Query Execution Error');
throw new ErrorException($InventoryCon->error, 701);
exit();
} else {
while ($Row = mysqli_fetch_assoc($Result)) {
$RowArray = array();
$RowArray[] = $Row['Pipeline'];
$RowArray[] = $Row['num_jobs'];
$RowArray[] = $Row['num_jobs'];
$RowArray[] = $Row['num_jobs'];
$RowArray[] = $Row['num_jobs'];
$AllRecords[] = $RowArray;
}
$output = array(
"draw" => 25,
"recordsTotal" => mysqli_num_rows($Result),
"recordsFiltered" => 25,
"data" => $AllRecords
);
//echo json_encode($AllRecords);
echo 200;
}
mysqli_close($InventoryCon);
}
error:
Status=200&StatusText=OK&Response=&Error=parsererror&Detail=SyntaxError: Unexpected token ‘i’, …”
if (isset(“… is not valid JSON
i was expenting the call to be made and get a result from ajax call
but every tile .fail function is being called
baltej pal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.