|
I don't understand what you mean, but I have, use ajax to do the login code, for your reference.
Here is the generic js script:
// JScript file, 2006-05-15--chx
// Public operations for ajax
function createRequestObject () // Create XMLHttpRequest object
{
var xmlhttp_request = null;
try {
if (window.ActiveXObject)
{
for (var i = 5; i; i--)
{
try {
if (i == 2)
{
xmlhttp_request = new ActiveXObject ("Microsoft.XMLHTTP");
}
else
{
xmlhttp_request = new ActiveXObject ("Msxml2.XMLHTTP." + i + ".0");
xmlhttp_request.setRequestHeader ("Content-Type", "text / xml");
xmlhttp_request.setRequestHeader ("Content-Type", "GB2312");
}
break;
}
catch (e)
{
xmlhttp_request = null;
}
}
}
else if (window.XMLHttpRequest)
{
xmlhttp_request = new XMLHttpRequest ();
if (xmlhttp_request.overrideMimeType)
{
xmlhttp_request.overrideMimeType ('text / xml');
//xmlhttp_request.overrideMimeType('GB2312 ');
}
}
}
catch (e)
{
xmlhttp_request = null;
}
return xmlhttp_request;
}
// Send an asynchronous request
function SendRequest (method, url, data, callback, isasyn) // callback This function gets the asynchronous return information and displays it, dada is a string
{
var xmlhttp = createRequestObject ();
with (xmlhttp)
{
try
{
// add random numbers to prevent caching
if (url.indexOf ("?")> 0)
{
url + = "&randnum =" + Math.random ();
}
else
{
url + = "? randnum =" + Math.random ();
}
open (method, url, isasyn);
// Set the request encoding method
// setRequestHeader ('Content-Type', 'application / x-www-form-urlencoded; charset = UTF-8');
setRequestHeader ('Content-Type', 'application / x-www-form-urlencoded; charset = GB2312');
if (data! = "")
{
send (data);
}
else
{
send ();
}
onreadystatechange = function ()
{
if (xmlhttp.readyState == 4) // determine whether the asynchronous call was successful
{
callback (xmlhttp);
xmlhttp = null;
}
}
}
catch (e)
{
alert (e);
}
}
}
Here is the actual code:
<script type = "text / javascript" src = "../ JScript / ajax.js"> </ script>
<script type = "text / javascript">
var serid = "";
function checkuser (object)
{
var thisid = object.id;
serid = thisid.substring (0, thisid.lastIndexOf ('_'));
public_getElementByID (serid + "_ ibtmLogin"). style.display = "none";
public_getElementByID ("divlogin"). innerHTML = "Login ... <br/> <img width = '170' src = '.. / Images / loader.gif' />";
var user = public_getElementByID (serid + "_ txtUserName"). value;
var pass = public_getElementByID (serid + "_ txtPassWord"). value;
SendRequest ("POST", "../ Pages / Check.aspx? Loginuser =" + user + "&pass =" + pass + "," ", checkok, true);
}
function checkok (http)
{
var response = http.responseText; // return the server-generated string
if (response == "Successful login")
{
public_getElementByID ("divlogin"). innerHTML = response;
window.location.href = "../ Default.aspx"
return;
}
else
{
alert (response);
public_getElementByID (serid + "_ ibtmLogin"). style.display = "block";
public_getElementByID ("divlogin"). innerHTML = "";
}
}
</ script>
Explanation: public_getElementByID () is my method that supports ec and ie, equivalent to document.getElementByID (). |
|