Please Help me with this i want to display the value in php echo using ajax call,
the code is running without error.
the value get displayed on console console.log(id)
when i select options from select field ,
and the value which i want to display using echo displays on console when i used console.log(data)
.
<script>
$('#select-user-id').click(function() {
var id = $(this).val();
$.ajax({
url: 'ajax.php',
type: 'POST',
data: {
id: id
},
success: function(data) {
console.log(id);
console.log(data);
}
});
})
</script>
But not displays on browser screen when i echo the value using.
$select_id = $_POST['id'];
echo "PHP: $select_id";
2
Answers
What you need to do is assign the value in a span or other html tags on success.
Just like what Ainz had mentioned, what you would want to do is send the value to a tag and display it there.
You can also append your variable to the string like below.