First of all, im sorry because im new on ajax and still learning it. I'm using google translate on my website page and i want to translate student_name from original text/string to arabic string. It is from table and i want to pass it to edit-student-data.php page. I have successfully get the arabic string and declare it to variable. And then, when i want to pass this variable to edit page the variable i cant get ajax value. Anyone can help me?
PHP
<table>
<thead>
<th>Student name</th>
</thead>
<tbody>
<tr>
<td class="student_name"><?php echo $take['student_name'] ?></td>
<td>
<a class="btn btn-warning editButton" href="index.php?page=edit-student-data&student_id=<?=$take['student_id'] ?>"> <i class="fas fa-pencil-alt" style=""></i> Edit</a>
</td>
</tr>
</tbody>
</table>
<script>
$(document).on('click', '.editButton', function(e) {
var tr = $(this).closest("tr");
var student_name_arabic = tr.find(".student_name").text();
alert(student_name_arabic); //SUCCESS
$.ajax({
type: 'POST',
url: 'edit-student-data.php',
data: { ar_name: student_name_arabic },
success: function(data)
{
$('#form-control').html(data);
}
});
});
</script>
Another PHP Page (edit student data page)
<div class="form-group">
<label for="exampleFormControlInput1">Student Name</label>
<input type="text" class="form-control" name="student_name" value="<?= $take['student_name'] ?>">
<?php
$ar_name = $_POST['ar_name'];
echo"<script>alert('$ar_name');</script>";
//I can't get arabic name value on alert. please help me:(
?>
</div>