07-14-2012, 12:11 AM
[eluser]shenanigans01[/eluser]
Hello, I'm using the following piece of code to ajax some form data to a controller:
In the controller, if the username is available it will Echo "GoodJob!", triggering the success function passing the string along and "GoodJob" will display in the div. If I want to trigger the Error function I have to change the output header to 4xx (406 for example). The problem with this is even if I echo "BadJob" it doesn't seem to be passed along. In firebug it still shows "badjob" as the response. Thoughts?
Hello, I'm using the following piece of code to ajax some form data to a controller:
Code:
$('#username').blur(function(){
var form_data = {
username : $("input#username").val()
};
$.ajax({
url: "http://localhost/auth/checkUsername/",
type: 'POST',
data: form_data,
success: function(msg) {
$('#username').removeClass('inputError');
$('#username').addClass('inputSuccess');
$("#success_message").html(msg).appendTo("form");
},
error: function(msg) {
$('#username').removeClass('inputSuccess');
$('#username').addClass('inputError');
$("#error_message").html(msg).appendTo("form");
}
});
return false;
});
In the controller, if the username is available it will Echo "GoodJob!", triggering the success function passing the string along and "GoodJob" will display in the div. If I want to trigger the Error function I have to change the output header to 4xx (406 for example). The problem with this is even if I echo "BadJob" it doesn't seem to be passed along. In firebug it still shows "badjob" as the response. Thoughts?