Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX/JQuery error when trying to send data
    primarykey
    data
    text
    <p>Not sure why, but I added an "error" clause to make sure the AJAX was failing... it is. It works correctly up to the AJAX portion, it's just not sending the data, no idea why.</p> <pre><code>&lt;script type="text/javascript"&gt; &lt;!-- $(document).ready(function() { $("#login").click(function() { document.getElementById("result").innerHTML = 'Validating credentials...'; var un = $("#un").val(); var pw = $("#pw").val(); if ( un == "" ) { document.getElementById("un_error").style.visibility = 'visible'; $("#un").focus(); } if ( pw == "" ) { document.getElementById("pw_error").style.visibility = 'visible'; $("#pw").focus(); } $.ajax({ type: 'POST', url: 'login-parse.php', data: { un: un, pw: md5(pw) }, success: function(msg) { document.getElementById("result").innerHTML = msg; }, error: function(xhr, status) { alert(status); } }); }); }); //--&gt; &lt;/script&gt; </code></pre> <p>That's the JS code.</p> <p>This is the HTML:</p> <pre><code> &lt;div id="content"&gt; &lt;div id="result" class="result"&gt;&lt;/div&gt; &lt;h2&gt;Login To Your Account&lt;/h2&gt; &lt;div class="text"&gt; &lt;fieldset&gt; &lt;fieldset&gt; &lt;legend&gt;Username&lt;/legend&gt; &lt;input type="text" id="un" value="" size="20" /&gt;&lt;span class="error" id="un_error"&gt;*&lt;/span&gt; &lt;/fieldset&gt; &lt;fieldset&gt; &lt;legend&gt;Password&lt;/legend&gt; &lt;input type="password" id="pw" value="" size="30" /&gt; &lt;span class="error" id="pw_error"&gt;*&lt;/span&gt; &lt;/fieldset&gt; &lt;input type="button" id="login" value="Login" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php // Login Parser require 'inc.common.php'; if (! isset ( $_POST['un'], $_POST['pw']) ) { echo '&lt;blockquote&gt;Invalid username/password combination.&lt;/blockquote&gt;' . "\n"; } else { $un = $_POST['un']; $pw = md5($_POST['pw']); $check = $sql-&gt;result ( $sql-&gt;query ( 'SELECT COUNT(*) FROM `users` WHERE `user_name` = \'' . $sql-&gt;escape($un) . '\' AND `user_password` = \'' . $sql-&gt;escape($pw) . '\'' ) ); $errors = array(); if (! strlen ( $un ) ) $errors[] = 'Please enter a valid username.'; if (! strlen ( $pw ) ) $errors[] = 'Please enter a valid password.'; if ( $check == 0 ) $errors[] = 'Invalid username/password combination.'; if ( count ( $errors ) &gt; 0 ) { echo '&lt;blockquote&gt;' . "\n", ' The following errors occurred with your login:' . "\n", ' &lt;ul&gt;' . "\n"; foreach ( $errors as $enum =&gt; $error ) { echo ' &lt;li&gt;&lt;strong&gt;(#' . ($enum+1) . '):&lt;/strong&gt; ' . $error . '&lt;/li&gt;' . "\n"; } echo ' &lt;/ul&gt;' . "\n", '&lt;/blockquote&gt;' . "\n"; } else { setcookie ( 'ajax_un', $un, time()+60*3600 ); setcookie ( 'ajax_pw', $pw, time()+60*3600 ); echo '&lt;blockquote&gt;' . "\n", ' &lt;p&gt;&lt;strong&gt;Success!&lt;/strong&gt;&lt;/p&gt;' . "\n", ' &lt;p&gt;You have successfully been logged in as &lt;strong&gt;' . $un . '&lt;/strong&gt;.&lt;/p&gt;' . "\n", ' &lt;p&gt;You may now return to the &lt;a href="index.php"&gt;index page&lt;/a&gt;.&lt;/p&gt;' . "\n", '&lt;/blockquote&gt;' . "\n"; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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