I’m posting some data to a php file with jquery. The PHP file just saves the data and prints the success of fail message. I would like to get the message generated by php file and embed in a div. I’m unable to figure out how i can return the message from PHP file.
Here is my code:
jQuery:
$(document).ready(function(){
$('#submit').click(function() {
$.ajax({
type : 'POST',
url : 'post.php',
data: {
email : $('#email').val(),
url : $('#url').val(),
name : $('#name').val()
},
});
});
});
PHP:
<?php
//save data
$message = "saved successfully"
?>
Try –
This uses the
successcallback of theajaxfunction to return your data back to the page within thedataparameter. The callback function then appends your data to a div on the page.You’ll also need to –
In your php page to give jQuery some data to work with.