Ajax returns as error, why?



this is my filesystem:


root:


source folder:



jquery.jquery.js
shoutbox.js
shoutbox.css


templates folder:



login.html.php
shoutbox.html
shoutbox.php


In templates -> login.html.php there is this file:



<!DOCTYPE html public transitional>
<html>
<head>
<title>Logga per entrare nellA SHOUT!</title>
</head>
<body>
<h1>Logga per entrare nella shoutbox!</h1>
<?php if (isset($logErr)): ?>
<?php echo "<p>" . $logErr . "</p>" ?>
<?php endif; ?>
<form method="post">
<div>
<label for="username">Username</label>
<input type="text" class="textbox" id="username" name="username">
</div>
<div>
<label for="password">Password</label>
<input type="password" class="textbox" id="password" name="password">
</div>
<div>
<select name="select" id="select">
<option id="anonimous" name="anonimous">Login as anonimo</option>
<option id="visible" name="visible">Login as visible</option>
</select>
</div>
<div>
<input type="submit" class="submit" name="submit" id="submit" value="Log In">
</div>
</form>
</body>
</html>


Then in shoutbox.php:



<?php

function IsUserLoggedIn() {

if(isset($_POST['submit']) && $_POST['submit'] == "Log In") {
if(! isset($_POST['username']) || $_POST['username'] == '' || ! isset($_POST['password']) || $_POST['password'] == '') {
$GLOBALS['logErr'] = "Please, filln all fields!";
return false;
}

if(isset($_POST['username']) && $_POST['username'] != '' && isset($_POST['password']) && $_POST['password'] != "") {
if(isset($_POST['select']) && $_POST['select'] == 'anonimous') {
session_start();

$_SESSION['loggedIn'] = TRUE;
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['type'] = $_POST['select'];
$_SESSION['ip'] = get_ip_address(); /* Return current ip */

$user = array(
"username" => $_SESSION['username'],
"islogged" => $_SESSION['loggedIn'],
"password" => $_SESSION['password'],
"ip" => $_SESSION['ip'],
"type" => $_SESSION['type']
);

echo json_encode($user);
return true;
}
else if(isset($_POST["select"]) && $_POST["select"] == "visible") {
session_start();

$_SESSION['loggedIn'] = TRUE;
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['type'] = $_POST["select"];
$_SESSION['ip'] = get_ip_address(); /* Return current ip */

$user = array(
"username" => $_SESSION["username"],
"islogged" => $_SESSION["loggedIn"],
"password" => $_SESSION["password"],
"ip" => $_SESSION["ip"],
"type" => $_SESSION["type"]
);
echo json_encode($user);
return true;
}
}
}
else if(isset($_POST['logout']) && $_POST['logout'] == "Log Out") {
session_start();

unset($_SESSION['loggedIn']);
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION["type"]);
unset($_SESSION["ip"]);
}

session_start();

if(isset($_SESSION["loggedIn"]) && $_SESSION["loggedIn"] == TRUE) {
return true; /* user is logged in */
}
else return false; /* user is not logged in */
}

if(IsUserLoggedIn() != false) {
include 'shoutbox.html';
}
else {
include 'templates/login.html.php';
}


And then, file source->shoutbox.js



$(function(){
sbUserIsLoggedIn = function(){
$.ajax({
url: 'shoutbox.php',
type: 'POST',
dataType: 'json',

success: function(user) {

CurrUserInfo = {
u_name: user["username"],
u_psw: user["password"],
ip: user["ip"],
typelog: user["type"],
logged: user["islogged"]
};

if(CurrUserInfo.typelog == "anonimous") {
OnlineListObj.onlineList.anonimous.push(user["username"]);
}
else if(CurrUserInfo.typelog == "visible") {
OnlineListObj.onlineList.visible.push(user["username"]);
}

OnlineListObj[onlineList][total] = OnlineListObj.onlineList.anonimous.length + OnlineListObj.onlineList.visible.length;

OnlineListObj[onlineList][phrase] = lang["there_are"] + OnlineListObj.onlineList.total + lang["online"] + OnlineListObj.onlineList.anonimous.length + lang["anonimous"] + OnlineListObj.onlineList.visible + lang["visibles"];

LoggedIn = true;

window.alert(LoggedIn);
window.alert(OnlineListObj[onlineList][total]);
window.alert(OnlineListObj[onlineList][phrase]);
window.alert(CurrUserInfo.ip);
window.alert(CurrUserInfo.typelog);
window.alert(CurrUserInfo.logged);
window.alert(CurrUserInfo.u_name);
window.alert(CurrUserInfo.u_psw);
},

error: function() {
sb_Error("Unknown error, try again");
console.log(lang["ajax_error"]);
window.alert("PROBLEM AAOASJJKJCBNCJBVN");

LoggedIn = false;
},
});
}
});


The function called error runs because ajax doesn't work....


Why this?


How to resolve?


you should see the alerts:



window.alert(LoggedIn);
window.alert(OnlineListObj[onlineList][total]);
window.alert(OnlineListObj[onlineList][phrase]);
window.alert(CurrUserInfo.ip);
window.alert(CurrUserInfo.typelog);
window.alert(CurrUserInfo.logged);
window.alert(CurrUserInfo.u_name);
window.alert(CurrUserInfo.u_psw);


..but they do not appear , again the same reason , ajax don't works...


My console.info



XHR finished loading: POST "http://localhost/Dev-JS-Jquery&PHP6/shoutbox.php".jquery.jquery.js:8628 jQuery.ajaxTransport.sendjquery.jquery.js:8164 jQuery.extend.ajaxshoutbox.js:304 sbUserIsLoggedInVM3177:2 (anonymous function)VM3151:847 InjectedScript._evaluateOnVM3151:780 InjectedScript._evaluateAndWrapVM3151:646 InjectedScript.evaluate
shoutbox.js:316 Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}abort: function ( statusText ) {always: function () {complete: function () {done: function () {error: function () {fail: function () {getAllResponseHeaders: function () {getResponseHeader: function ( key ) {overrideMimeType: function ( type ) {pipe: function ( /* fnDone, fnFail, fnProgress */ ) {progress: function () {promise: function ( obj ) {readyState: 4responseText: "
↵<html>
↵<head>
↵ <script src="source/jquery.jquery.js"></script>
↵ <link href="source/ui/ui.jquery.css" rel="stylesheet" type="text/css">
↵<script src="source/ui/ui.jquery.jquery.js"></script>
↵<link href="source/shoutbox.css" rel="stylesheet" type="text/css">
↵<script src="source/shoutbox.js"></script>
↵</head>
↵<body>
↵<div id='loading_screen'><h1>Loading...</h1></div>
↵</body>
↵</html> "setRequestHeader: function ( name, value ) {state: function () {status: 200statusCode: function ( map ) {statusText: "OK"success: function () {then: function ( /* fnDone, fnFail, fnProgress */ ) {__proto__: Object


Help me, please!


No comments:

Post a Comment