i have a problem with my ajax script. I want to make the form filled automatically by select the user_id. But it didn't work. I use jquery ver. 3.5.1 and this is my code:
<form class="form-horizontal" action="" method="post">
<div class="form-group row">
<div class="col-sm-8">
<div class="form-group row">
<label for="user_id" class="col-sm-4 col-form-label">User ID</label>
<div class="col-sm-8">
<select class="form-control" name="user_id" id="user_id" onchange="chcek_database()">
<option value="" selected="">User ID</option>
<?php
include "connection.php";
$query=mysqli_query($con,"select * from customer");
while ($data=mysqli_fetch_array($query)){
echo "<option value='$data[user_id]'>$data[user_id]</option>";
}?>
</select>
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-4 col-form-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="name" id="name">
</div>
</div>
</form>
and it's the ajax script
<script type="text/javascript">
function check_database(){
var user_id = $("#user_id").val();
$.ajax({
url: 'ajax.php',
data: "user_id="+user_id ,
}).success(function (data) {
var json = data,
obj = JSON.parse(json);
$('#name').val(obj.name);
});
}
<?php
include 'connection.php';
$nim = $_GET['user_id'];
$query = mysqli_query($con, "SELECT * FROM customer WHERE user_id= '$user_id'");
$customer = mysqli_fetch_array($query);
$data = array(
'name' => $customer['name'],);
echo json_encode($data);
?>
and when i try to select the user_id, the name won't shown. i try to check the console with inspect the google chrome and it's the error message said:
(index):406 Uncaught TypeError: $.ajax(...).success is not a function
at cek_database ((index):406)
at HTMLSelectElement.onchange ((index):61)
cek_database @ (index):406
onchange @ (index):61
How to fix it? hope you guys would to give me the answer. Thank you.