I am using this js code for an ajax request and getting the data, this code works well & show the data in the textbox. But for some reasons, I want to get the value of js variable id1 into php code(index.php). I tried but not able to get the value of id1 into php code, plz help.
HTML CODE:(index.php)
<body>
<input type="text" name="urn_no" ID="urn_no" value=""/>
<input type="number" name="mob_1" ID='mob_1' value="" onkeydown="getData(this.value);" />
</body>
JS CODE:(code in index.php)
function getData(val) {
$.ajax({
type: "POST",
url: "test.php",
dataType: "json",
data:'dt='+val,
success: function(data){
var len = data.length;
if(len > 0){
var id1 = data[0]['id1'];
// Set value to textboxes
document.getElementById('urn_no').value = id1;
}
}
});
}
PHP CODE(test.php)
<?php
if (! empty($_POST["dt"])) {
$sql="SELECT * FROM call_data WHERE U_no = '".$_POST["dt"]."'";
$result = mysqli_query($con,$sql);
if(!$result || mysqli_num_rows($result)<=0) {
}
$users_arr = array();
while( $row = mysqli_fetch_array($result) ) {
$r1=$row['URN_Number'];
$users_arr[] = array("id1" => $r1);
}
echo json_encode($users_arr);
exit;
}
?>