One thing you should decide early on is what formate you want to use for the responses. Many times it is ok to just request html as a response but when you are working with big or more complex datasets you usually will want ther response text to be xml or json (which I use most of the time). The reasoning behind this is that xml and json are structured data that can be manipulated after arrival whereas html you will usually just want to append or replace with parts of the already existing web page.
Between xml and json I prefer json because of the small data overhead, on all other points both formats are pretty much the same except if you want to send object methods in your response in which case json is the only way to do it conveniently.
Between xml and json I prefer json because of the small data overhead, on all other points both formats are pretty much the same except if you want to send object methods in your response in which case json is the only way to do it conveniently.
Index.html (View Page )
$.ajax({
type: 'POST',
url: 'save-user.php',
data: { fname: "manish", email: "manishkp22@gmil.com", role:"admin"},
success: function(data) {
console.log(data);
if(data == 'error')
{
$('#Register_error').text('Must Be filled...');
$('#Register_error').show();
}
else {
$('#Register_error').hide();
$('#Register_success').text('Successfully submit');
$('#Register_success').show();
}
}
});
save-user.php (Model Page)
<?php
$fname = $_POST['fname'];
$email = $_POST['email'];
$role = $_POST['role'];
if(!empty($fname) && !empty($email) && !empty($role))
{
#MYSQL CONNECTION QUERY #
echo"success";
}
else{
echo "error";
}
?>
Comments
Post a Comment