Saturday 15 September 2012

php - Ajax fail no response -


I have a login page when I am working the correct login data ajax. But when I do not return the wrong login or password script, the error returns the error. How do I fix it, where do I make a mistake on the code? Ajax script

  function getdetails () {var name = $ ('# user'). Val (); Var hello = $ ('#pass'). Val (); Var request = $ Ajax ({type: "POST", url: "login.php? Id = 0", data: {login: name, pass: haslo}}); Request.fail (function () {warning ("test");}); Request.done (function () {$ ('# logowanie'). Load ('index.php #logowanie');}); };   

form code

  function logowanie () {if (isset ($ _ session ["Login to"]) & amp; ; $ _SESSION ["Login to"]! == 0) {echo '& lt; Div id = "logowanie" & gt; Vitas'. $ _ Session ['nick']. ' No platform '; Echoes' & lt; Br / & gt; & Lt; A href = "login.php? Off = 1" & gt; Wyloguj & lt; / A & gt; & Lt; Br / & gt; '; If ($ _ session ['power']> gt;) {echo '  

Check form

  function werfikuj () {$ login = $ _ post ['log']; $ Haslo = $ _ post ['pass']; $ Zapytanie = 'Select * from those users where login = "'. $ Login." "And hello =" '. MD5 ($ hello) '' '; '; $ Result = $ this- & gt; Db- & gt; Query ($ zapytanie); If ($ result-> num_rows == 1) {echo "Zalovano poprawany"; $ Line = $ result- & gt; Fetch_asoc (); $ _SESSION ['Login'] = $ line ['id']; $ _SESSION ['Nick'] = $ line ['login']; $ _SESSION ['power'] = $ line ['power'];} and (die) (json_encode ('zly login lub haslo'));}}   

thx for help

Ajax, you do not know if you want to show an error to call ajax, your" Zalogowano Poprawnie "message and encoded 'zali login lub hello' message is meaningless for me (i do not know your language). If you want to tell Ajax it is an error, you need to respond with a different HTTP response code. The 'failed' method is called only when there is an HTTP error response.

If you are using PHP5,

  echo json_encode ('zly login lub haslo'); Http_response_code (404); Go out();   

By the way, I do not know your intention to use json_encode, it can not solve your problem eventually, but I believe that it answers that why you 'error' Not getting

Alternatively, you can always return a 'OK' or 'failed' message. Ajax will always call the 'done' method. Inside the 'done' method, you perform different actions according to the message ('ok' or 'unsuccessfully')

No comments:

Post a Comment