jquery success / error? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: jquery success / error? (/showthread.php?tid=53189) |
jquery success / error? - El Forum - 07-14-2012 [eluser]shenanigans01[/eluser] Hello, I'm using the following piece of code to ajax some form data to a controller: Code: $('#username').blur(function(){ 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? jquery success / error? - El Forum - 07-14-2012 [eluser]Crackz0r[/eluser] If im not wrong, you will get a TRUE or FALSE response, unles you use JSON, i.e. to "echo" a response. Check this little example of how to fetch data using JSON, jQuery and PHP http://www.electrictoolbox.com/json-data-jquery-php-mysql/ Regards. jquery success / error? - El Forum - 07-14-2012 [eluser]vitoco[/eluser] "success" and "error" are functions to reflect the proper communication with the server, not the logic of the result in the app, so don't mess with that. To solve your question, first define which type of return you wanna send from the server to the client, like plain text, xml, json. I'll show you how to work with json. Code: $('#username').blur(function() In the controller Code: function checkUsername() Saludos |