My Question is little complicated, But experts may understand what i am trying to ask.
I have the following code in Jquery which submits a form and display the validation result from the destination page.
submitHandler : function(form) {
if($('#login').submit(function(){return false;}))
{
$.ajax
({
type: 'POST',
url: $('#login').attr('action'),
data: $('#login').serialize(),
success: function(data)
{
$('#results').html(data);
}
});
}
return false;
},
The destination page is in php. The content displayed in #results is php processed validation results
My Issue is - Iam getting some alpha numeric strings with the validation result as follows
{"output":"","status":-1,"error_messages":{"error":["please enter your name."],"success":[]}}
This is because i have a php file called message.php this validation results should be come through message.php. it is exaclty processing and stripping the unwanted charectors and displays the error message properly.
Is there any way to do this in the above JavaScript(Jquery)that the the validation results should come through message.php instead of direct displaying to avoid putting unwanted characters in validation results (only validation result should be displayed)..
Or any other suggestions you have ?
Looking forward for a favorable action from an expert..
Regards TOM
ADDITIONAL INFORMATION When turning off the browsers JavaScript the result is producing correctly, because the form is not submitting through jquery-Ajax (through form action="") and validation messages come through messages.php.
The messages are displaying as
<?php
echo $messages;
?>
I'm ignoring data['output']
and data['status']
because i don't really know how you plan to use them and what values they could have. I'll assume that the success or error message returned is sufficient for the user.
It looks like data
contains JSON so why not pull out the relevant success or error message?
...
success: function(data)
{
var msg = data['error_messages']['success'][0] != '' ? data['error_messages']['success'][0] : data['error_messages']['error'][0] ;
$('#results').html( msg );
}
...