k, what I want this script to do is send the username and password the user inputed into the form to the php via the javascript (using sajax), then show what the php returns (either the error, or the success messsage). All I'm am getting is "undefined", and not one of the messages. My problem is with the javascript (as fare as I know my php is fine). The error would be with the send-receive function:
Code:
function login(){
username = document.getElementById("user").value;
password = document.getElementById("pass").value;
sajax_request_type = "POST";
x_login(username, password, get);
}
I think its sending the username and password to the php, but its just not getting the return message. Thats were I need help. How would I make the javascript send the username and password to the php and display what the php returns within one function? I know how to do this with two functions on each side (two javascript functions and two php functions as shown below)
Code:
<?php
require("Sajax.php");
sajax_init();
sajax_export("getpageid", "submit");
sajax_handle_client_request();
function getpageid() {
include('inc/database.php');
return $pageid;
}
function submit($data){
include('inc/database.php');
mysql_query("UPDATE pages SET pageid='$data' WHERE pageid='$pageid'");
return getpageid();
}
?>
<html>
<head>
<title>SQL DB</title>
<script>
<?
sajax_show_javascript();
?>
function show_pid(z) {
document.getElementById("z").value = z;
}
function get(){
setTimeout("x_getpageid(show_pid)", 10);
}
function dis(){
document.getElementById("savestat").innerHTML = "";
document.getElementById("y").value = "";
change('savestat', 'hidden');
document.getElementById("z").disabled=false;
}
function savestat(){
if(document.getElementById("y").value != data){
change('savestat', 'show');
document.getElementById("z").disabled=true;
document.getElementById("savestat").innerHTML = "Saving...";
setTimeout("savestat()", 10);
}else{
document.getElementById("savestat").innerHTML = "Saved!";
setTimeout("dis()", 2500);
}
}
function updateid(d){
setTimeout("document.getElementById('y').value = data", 0);
}
function submit(){
data = document.getElementById("z").value;
sdata = document.getElementById("y").value;
sajax_request_type = "POST";
x_submit("" + "" + "" + data, get());
savestat();
updateid(data);
}
function change(id, newClass)
{
identity=document.getElementById(id);
identity.className=newClass;
}
</script>
<style type="text/css">
#savestat{
position:relative;
top:-24px;
background-color:#eeeeee;
color:#bf1900;
width:205px;
height:20px;
text-align:center;
padding-top:2px;
border:1px solid #000000;
filter:alpha(opacity=90);
opacity: 0.9;
-moz-opacity:0.9;
}
.hidden{
display:none;
}
.show{
display:block;
}
</style>
</head>
<body onload="get();dis();">
<form action="javascript:submit()" onsubmit="submit()">
<input type="hidden" name="y" id="y" value="" />
<input type="text" name="z" id="z" value="" size="30" />
<input type="submit" name="check" value="Update ID" />
<div id='savestat' class='hidden'></div>
</form>
</body>
</html>
The above code gets the id of a page I pre-defined, shows it in a form input, and when the form is submitted, updates the id of that page with what-ever was in the input box when the form was submitted. This code should give you a better idea of what I'm after.
I think I have explained my problem, and if you could help me solve if, that you be grate.
Bookmarks