I have the following code to retrieve data from MySQL. The following test suggests that something is wrong with the ajax part because the 'ttt' alert does not execute. What am I missing?
function autoFill() {
var claimantIDs = document.getElementById('claimant_search').value;
alert(claimantIDs);
$.ajax({
type: "POST",
url: "get_claim.php",
data: {ID, claimantIDs},
dataType: "json",
success: function(data){
alert("ttt");
}
});
alert("END");
}
the relevant php is:
<?php
require_once('../dbconnect.php');
$ID = $_POST['ID'];
$result = mysql_query("select * from 1tbl_CLAIMANT_DETAIL where ID = '".$ID."' ") or die(mysql_error());
$row = mysql_fetch_array($result);
$data = json_encode($row);
echo $data;
?>
In your AJAX part, look at the way you are passing value through POST method
$.ajax({
type: "POST",
url: "get_claim.php",
data: {ID, claimantIDs},// <-- problem
dataType: "json",
success: function(data){
alert("ttt");
}
});
data field in AJAX required a JSON object which should be key value pair, but you are directly passing the value and I assume that due to this your PHP code is not able to get the values that's why your code is not running properly. You should also inlcude the error method inside you AJAX call.
Hi,
In your ajax code way your data passing is wrong I think.
Please try this
data: {ID: claimantIDs},
in your ajax code segment .
Try to debug your get_claim.php file by printing $_REQUEST variables like this at the top of your file
<?php
echo '<pre>';
print_r($_REQUEST);
echo '</pre>';
die();
?>
If you are able to see the data which you passed by ajax then your ajax is working fine. Also check into network, weather the url is hitting properly or not.
Problem is here. {ID, claimantIDs},
Change it to {'ID' : claimantIDs},
Also, Change mysql to mysqli
as mysql
is deprecated version. You will not be able to use it in the latest PHP versions.