Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX/JQuery Internal Server Error 500
    primarykey
    data
    text
    <p>I have tried many solutions; I've debugged with FireBug and the error makes no sense. I have other pages I've made similar to this that work perfectly. The headers are being sent correctly, and the response that is displayed in FireBug is actually the correct response text; but it just doesn't display it on the page! Instead it returns "Internal Server Error 500" and I don't understand why.</p> <p>Here are my pages:</p> <p>First one is my class page that handles new page creation, just so you could see how the javascript scripts are referenced:</p> <pre><code>&lt;?php // Page Class class Page { public $title; function __construct ( $pageTitle = '', $scripts = "" ) { global $config; if ( strlen ( $pageTitle ) &gt; 0 ) { $this-&gt;title = $config['site']['name'] . ' &amp;raquo; ' . $pageTitle; $usePTitle = 1; } else { $this-&gt;title = $config['site']['name']; $usePTitle = 0; } echo '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;' . "\n", '&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en"&gt;' . "\n", '&lt;head&gt;' . "\n", ' &lt;title&gt;' . $this-&gt;title . '&lt;/title&gt;' . "\n", ' &lt;link rel="stylesheet" type="text/css" href="default.css" /&gt;' . "\n", ' &lt;script type="text/javascript" src="scripts/jquery.js"&gt;&lt;/script&gt;' . "\n", ' &lt;script type="text/javascript" src="scripts/functions.js"&gt;&lt;/script&gt;' . "\n"; if ( strlen ( $scripts ) &gt; 0 ) { echo ' &lt;script type="text/javascript"&gt;' . "\n", ' &lt;!--' . "\n"; include 'scripts/' . $scripts; echo ' //--&gt;' . "\n", ' &lt;/script&gt;' . "\n"; } echo '&lt;/head&gt;' . "\n", '&lt;body&gt;' . "\n", ' &lt;h2&gt;' . ( $usePTitle == 1 ? $pageTitle : $config['site']['name'] ) . '&lt;/h2&gt;' . "\n", '&lt;hr class="nv" /&gt;' . "\n", $this-&gt;head(); } function head ( ) { global $user, $sql, $config; if ( $user-&gt;auth == true ) { $pmc = $sql-&gt;result ( $sql-&gt;query ( 'SELECT COUNT(*) FROM `private_msgs` WHERE `pm_user` = ' . intval ( $user-&gt;info['id'] ) ) ); $headLinks = array ( 'Control Panel' =&gt; 'user.php', 'Private Messages (' . $pmc . ')' =&gt; 'messages.php', 'Logout' =&gt; 'logout.php', 'Contact Us' =&gt; 'contact.php' ); echo ' &lt;div id="userbar"&gt;' . "\n", $user-&gt;info('name') . ' (' . $user-&gt;info('level') . ') ' . "\n", ' &lt;ul id="userlinks"&gt;' . "\n"; foreach ( $headLinks as $t =&gt; $l ) { echo ' &lt;li&gt;&lt;a href="' . $l . '"&gt;' . $t . '&lt;/a&gt;&lt;/li&gt;' . "\n"; } echo ' &lt;/ul&gt;' . "\n", ' &lt;/div&gt;' . "\n", '&lt;hr class="nv" /&gt;' . "\n"; } else { $headLinks = array ( 'Register' =&gt; 'register.php', 'Login' =&gt; 'login.php', 'Contact Us' =&gt; 'contact.php' ); echo ' &lt;div id="userbar"&gt;' . "\n", ' Guest (' . $config['levels']['guest'] . ') ' . "\n", ' &lt;ul id="userlinks"&gt;' . "\n"; foreach ( $headLinks as $t =&gt; $l ) { echo ' &lt;li&gt;&lt;a href="' . $l . '"&gt;' . $t . '&lt;/a&gt;&lt;/li&gt;' . "\n"; } echo ' &lt;/ul&gt;' . "\n", ' &lt;/div&gt;' . "\n", '&lt;hr class="nv" /&gt;' . "\n"; } } function restrict ( $lvl ) { global $user; if ( $user-&gt;info('level') &lt; $lvl ) { echo ' &lt;h2&gt;Authorization Error&lt;/h2&gt;' . "\n", ' &lt;div class="text"&gt;' . "\n", ' You are not authorized to view this page.' . "\n", ' &lt;/div&gt;' . "\n", '&lt;hr class="nv" /&gt;' . "\n"; $page-&gt;genFooter(1); } } function genFooter ( $die = 0 ) { $year = date ( 'Y', time() ); $copy = ''; echo ' &lt;div id="footer"&gt;' . "\n", ' &amp;copy;' . $year . ' ' . $copy . "\n", ' &lt;/div&gt;' . "\n", '&lt;/body&gt;' . "\n", '&lt;/html&gt;'; if ( $die == 1 ) die(); } } ?&gt; </code></pre> <p>The next page is my actual login.php page that the logins are supposed to be run with:</p> <pre><code>&lt;?php require 'inc.common.php'; $page = new Page ( 'Login', 'login.js' ); ?&gt; &lt;div id="content"&gt; &lt;div id="result" class="result"&gt;&lt;/div&gt; &lt;h2&gt;Login&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 id="un_error" class="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 id="pw_error" class="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;/body&gt; &lt;/html&gt; </code></pre> <p>The next page is my "login.js" page that contains the JavaScript/AJAX code:</p> <pre><code>$(document).ready(function() { $("#login").click(function() { document.getElementById("result").innerHTML = 'Validating login...'; var user = $("#un").val(); var pass = $("#pw").val(); if ( user == "" ) { document.getElementById("un_error").style.visibility = 'visible'; $("#un").focus(); } if ( pass == "" ) { document.getElementById("pw_error").style.visibility = 'visible'; $("#pw").focus(); } $.ajax({ type: "POST", url: "http://stjohnspikapp.org/ajaxforums/login-parse.php", data: "un=" + user + "&amp;pw=" + pass + "&amp;session=" + Math.random(), success: function(msg) { document.getElementById("result").innerHTML = msg; } }); }); </code></pre> <p>});</p> <p>The final page is the login-parse.php page which is what receives the AJAX request and sends a response...</p> <pre><code>&lt;?php require 'inc.common.php'; $uname = $_POST['un']; $pword = $_POST['pw']; $errors = array(); if (! strlen($uname) ) $errors[] = 'Invalid username.'; if (! strlen($pword) ) $errors[] = 'Invalid password.'; $check = $sql-&gt;query('SELECT * FROM `users` WHERE `user_name` = \'' . $sql-&gt;escape($uname) . '\' AND `user_password` = \'' . $sql-&gt;escape(md5($pword)) . '\'' ); if ( $sql-&gt;num_rows ( $check ) == 0 ) $errors[] = 'Invalid username/password combination.'; /*if ( count ( $errors ) &gt; 0 ) { echo '&lt;blockquote&gt;The following errors occurred while processing your request:' . "\n", '&lt;ul&gt;' . "\n"; foreach ( $errors as $enum =&gt; $e ) { echo ' &lt;li&gt;&lt;strong&gt;(#' . ($enum+1) . '):&lt;/strong&gt; ' . $e . '&lt;/li&gt;' . "\n"; } echo '&lt;/ul&gt;' . "\n", '&lt;/blockquote&gt;' . "\n";*/ if ( count ( $errors ) &gt; 0 ) { echo '&lt;blockquote&gt;There was an error with your submission.&lt;/blockquote&gt;' . "\n"; } else { setcookie ( 'ajax_un', $uname, time()+60*3600 ); setcookie ( 'ajax_pw', $pword, time()+60*3600 ); echo '&lt;blockquote&gt;' . "\n", ' You have been logged in successfully!&lt;br /&gt;' . "\n", ' You may now return to the &lt;a href="index.php"&gt;board index&lt;/a&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.
    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. 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