php - Jquery Ajax error handling fail -


i'm trying handle errors sent php script. here code:

<script> $(document).ready(function() {     $('#signupform').submit(function() {         $.ajax({             type: 'post',             url: "process.php",             data: $("#signupform").serialize(),             success: function(data) {                 if ((data == "incorect email format.") || (data == "username must between 6-32 signs , include 0-9, a-z   characters.") || (data == "password must between 8-32 signs , include 0-9, a-z characters.") || (data == "passwords not match.") || (data == "username taken, please try one.")) {                     $('#errors').show();                     $('#errors').html(data);                 } else {                     window.location.href = "http://localhost:8888";                 }             }         });         return false;     }); });  </script> 

firebug shows response sent errors aren't displayed. problem? thanks.

so according our discussion in comments , having new response sent server in json format, here how can render errors:

assuming following response (always validate json response on site this):

[{"status":"1","data":"incorrect email format."},{"status":"2","data":"username must min 6 signs , include 0-9, a-z characters."},{"status":"3","data":"password must min 8 signs , include 0-9, a-z characters."}] 

now if getting response in success function here how can render them on html:

success: function (data) {     if (data) {         $.each(data, function (index, obj) {             $('#error').append('<div>' + obj.data + '</div>');         });     } } 

here jsfiddle showing in action


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -