I have a login page, which sends an AJAX request to the server when someone tries to log in. AJAX, the server goes on, I have been able to confirm due to the logging they have. But the problem is that my jacose is not getting JSON
My controller has a function:
public function login () {$ this- & Gt; Load-> Model ('users_model'); If ($ !! -> it-> Input-> Post ('email')) || ($$$ -; -> Input-> Post ('password')) {$ ret = $ this- & gt; User_model- & gt; Login ($ this-> Input-> Post ('email'), $ this-> Input-> Post ('password')); Echo json_encode (array ('position' => gt; "OK", 'msg' = & gt; 'log in!')); // also tried to return} and {echo json_encode (array ('condition' => gt; 'FAIL', 'msg' = & gt; 'invalid email or pass')); }} and the AJAX function is:
& lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("# login") .jaxform (function (jason) {alerts (js); if (jsn.status == true) {warning (JSON.mms); // Window.location = '& lt ;? php echo base_url ();? & Gt;';} Other {warning ("problem"); $ (". Error_msg"). Html (json.msg);};}) ;}); & Lt; / Script & gt; If I warn the json variable, it is empty, and if I do json.msg, then it is undefined. So ... what do I have to do to give a callback, a Jason object, or any kind of object? Please explain it, so I understand this problem, not to fix it. Thanks a lot!
Edit: Here's the form:
& lt; Span class = "error_msg" & gt; & Lt; / Span & gt; & Lt; / Br & gt; & Lt; Form id = "login" action = "& lt ;? php echo base_url ();? & Gt; user / login" method = "POST" enctype = "multipart / form-data" & gt; Email: & lt; Input name = "email" type = "text" / & gt; & Lt; / Br & gt; Password: & lt; Input type = "password" name = "password" & gt; & Lt; / Br & gt; & Lt; Input type = "submit" / & gt; & Lt; / Form & gt;
Ah, I think I understand.
Is this plugin used?
In that case, submit AJAX , not ajaxform . In other examples, do something like this online:
$ (document) .ready (function () {$ ('# login'). Submit (function () { $ ("# Login"). Ajax submit ({success: function (json) {alert (Json); if (json.status == true) {warning (json.msg); //window.location = '& lt ;; Php echo base_url ();? & Gt; ';} Other {warning ("problem"); $ (". Error_msg"). Html (json.msg);}}}); return false;}); });
No comments:
Post a Comment