Господа, очередная проблема. Открыл для себя Ajax(реализация - Sajax), решил перевести логин сайта на него. Но вот тут и проблема. Напсанный код не отрабатывает, я грешу на JS(в котором опыта мало), но ошибку найти не могу. | Код | <?php session_start(); session_register("user"); require("config.php"); require("Sajax.php"); $sajax_debug_mode=1; function printLogin($username,$error) { ob_start(); if ( $error ) { ?><p align="center"><font color="red"><?= $error ?></font></p><? } ?> Login: <input id="login" type="text" value="" ><br > Password: <input id="pass" type="pass" value="" ><br> <input type="button" value="Login" onClick="x_login(document.getElementById('login').value,document.getElementById('pass').value,do_cb);" /> <? $html = ob_get_contents(); ob_end_clean(); return setData('data',$html); }
function printMenu() { if ( $_SESSION["user"] == "" ) { return printLogin('',''); } ob_start(); ?> <h5>тест</h5> <? $html = ob_get_contents(); ob_end_clean(); return setData('data',$html); }
function login($login,$pass) { $link = mysql_connect("$DBHOST", "$DBUSER", "$DBPASS") or die("Could not connect : " . mysql_error()); mysql_select_db("$DBNAME") or die("Could not select database");
if (strlen($_REQUEST['login'])==0 || strlen($_REQUEST['pass'])==0){ header("Location: login.php"); die('Ошибка в логине или пароле');
}else { $user_result = mysql_query("SELECT * FROM users WHERE login='".mysql_escape_string($_REQUEST['login'])."' AND pass='".md5($_REQUEST['pass'])."'");
if (mysql_error()){ header("Location: login.php"); die(mysql_error());
} elseif (@mysql_num_rows($user_result) != 1){ header("Location: login.php"); die('Ошибка в логине или пароле'); } else { if ( $row = mysql_fetch_row($user_result)) { $_SESSION["user"] = $row[0]; mysql_free_result($result); mysql_close($link); return printMenu(); } else { mysql_free_result($result); mysql_close($link); return printLogin($username,"The username/password pair could not be authorized. Please try again."); } }}}
function fix_html($html) { $patterns = array( "/\n/", "/\r/" ); $replace = array( "\\n", "\\r" ); $fix = addslashes($html); $fix = preg_replace($patterns,$replace,$fix); return $fix; }
function setData($div,$data) { $html = "document.getElementById('$div').innerHTML='" .fix_html($data)."'"; return $html; } sajax_init(); sajax_export("printLogin","login","printMenu"); sajax_handle_client_request(); ?> <html> <head> <title>Login Sajax</title> <script> <? sajax_show_javascript(); ?> function do_cb(result) { document.getElementById('data').innerHTML=''; eval(result); } </script> </head>
<body onLoad="x_printMenu();"> <div id="data"></div> </body>
|
Выдает белый лист, а дебагер пишет: Caught error [Error: name: TypeError message: Statement on line 135: Type mismatch (usually a non-object value used where an object is required) Backtrace: Line 135 of inline#1 script in http://localhost/foto/quest_test.php callback(eval(data), extra_data); At unknown location [statement source code not available] ]: Could not eval var res = 'document.getElementById(\'data\').innerHTML=\' <h5>re</h5>\\r\\n \''; res; Это сообщение отредактировал(а) Somebody32 - 17.9.2006, 11:49
|