I’m trying to populate an element after an ajax call is made, but I’m not too sure whether this is the right way to do it and if it is, where I’m going wrong.
Here’s my code…
$(document).ready( function() {
$("#edit_delete").click(function() {
$.post('mySelect.php', $("#edit_delete").serialize(), function(result) {
$('#message1').html(<?php echo $myTest; ?>);
$('#message2').html(<?php echo $myOtherTest; ?>);
});
}
});
mySelect.php :
<?php include '../../includes/connection.php' ?>
<?php
$selected_user = $_POST["users"];
$result = mysql_query("SELECT * FROM users WHERE id = $selected_user");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
?>
<?php $myTest = $row['id']; ?>
<?php $myOtherTest = $row['name']; ?>
<?php mysql_close($con); ?>
(Let me know if you need more info and please feel free to edit my question so it makes sense!)
No, you should echo your data back to the client and then use it
And then
You do this because you are making an asynchronous call to the server: you don’t reload your page, you just make a call and get some data back