Reputation: 1755
I am working on a a script to process the form submission based on AJAX. I am able to submit the form using AJAX and show a success message. However I want to show different messages based on background form data processing. For example, when the user registration form is submitted it is being entered into 2 systems, so I want to show - User created in system One then user created in system 2, then an email is being sent, so I want to show email is being sent. and so on.
I am currently using the jquery ajax method. here is my sample code.
formData = jQuery('form#Registration').serialize();
jQuery.ajax({
url: 'form_process.php',
type: 'POST',
data: formData,
dataType: 'html',
success: function (msg, textStatus, xhr) {
jQuery('#success_msg').html( msg );
}
});
So how I can show different messages base on data processing.
Thanks
Upvotes: 0
Views: 51
Reputation: 3037
Here we have login.js. we will get the data from login form. i think you will understand from the given code.
var adminlogin={
init:function(){
this.formSubmitEvent();
},
formSubmitEvent:function(){
_this=this;
$("#adminlogin-form").submit(function(){
if((result=formValidation("adminlogin-form"))&&(result['error']))
{
return false;
}
data=getFormObj("adminlogin-form");
_this.login(data);
return false;
});
},
login:function(data){
$.ajax({
url:"admin/login.php",
data:data,
success:function(data){
if(data.adminid)
{
window.location = "home.php";
}else
{
showError(data.reason);
}
},
error:function(data){
if(data.responseText=="")
{
showError("Some error occured in server");
}
else
{
showError(data.responseText);
}
}
});
}
};
adminlogin.init();
try like this
Upvotes: 1
Reputation: 74738
So, for this you need to do your processings at the serverside and then you can echo out the message you want to show:
if(condition){
echo "User created in system One.";
} else if(condition){
echo "User created in system Two.";
}else{
echo "Email sent.";
}
now at the jQuery.ajax()
you need to change the dataType
to:
dataType:"text"
Upvotes: 1