Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is my preferred option. Not saying it's perfect but it's what I've been using for a while. Just means that all your error messages are stored in PHP rather than in your JS files (which I prefer). Also note, the below code is untested.</p> <p><strong>Edit</strong>: <em>Just a note as to why I prefer the errors in PHP instead of JS. I normally have a table with my errors in, meaning I can output the error code and message just by saying <code>oh this is ERR-002, output the message associated with it</code>. When somebody phones up with ERR-002, I only need to check the DB (and not trawl through code).</em></p> <p>On your login.php page, you can return a json encoded array that javascript can decode. So in your php:</p> <pre><code>&lt;?php $arrResult = array("message" =&gt; "Could not log you in", "type" =&gt; "error"); // Or the success one: // $arrResult = array("message" =&gt; "You're logged in", "type" =&gt; "success"); echo json_encode($arrResult); ?&gt; </code></pre> <p>Then you can decode this message and use it as an object in javascript, like so:</p> <pre><code>function DisplayLoginError() { var loginForm = document.loginForm; var dataString = $(loginForm).serialize(); $.ajax ({ type: 'POST', url: 'login.php', data: dataString, success: function(strResponse){ var $objResponse = $.parseJSON(strResponse); if ($objResponse.type == "success") { window.location = "home/"; } else { $('#signinAlert').html($objResponse.message).css('display','block'); } } }); return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload