Code:
var xmlDoc;
function add()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("users.xml");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("users.xml");
}
else
{
alert('Your browser cannot handle this script');
}
alert('now executing addUser func');
function addUser()
{
var newPHPXML = '%3C?xml%20version=%221.0%22%20encoding=%22ISO-8859-1%22?%3E';
var users = parseFloat(xmlDoc.getElementsByTagName("excalo")[0].getAttribute("users"));
var users2 = parseFloat(xmlDoc.getElementsByTagName("excalo")[0].getAttribute("users"))+1;
var encPass = encrypt(document.register.password.value, 'aouenxlcjh');
newPHPXML+='%3Cexcalo%20users=%22' + users2 + '%22%3E';
var i = 0;
for(i=0; i<users; i++)
{
var x = i
newPHPXML+='%3Cuser%20username=%22' + xmlDoc.getElementsByTagName("user")[x].getAttribute("username") + '%22%3E';
newPHPXML+='%3Cname%3E' + xmlDoc.getElementsByTagName("name")[x].childNodes[0].nodeValue + '\%3C/name%3E';
newPHPXML+='%3Cage%3E' + xmlDoc.getElementsByTagName("age")[x].childNodes[0].nodeValue + '\%3C/age%3E';
newPHPXML+='%3Cpassword%3E' + xmlDoc.getElementsByTagName("password")[x].childNodes[0].nodeValue + '\%3C/password%3E';
newPHPXML+='%3Cemail%3E' + xmlDoc.getElementsByTagName("email")[x].childNodes[0].nodeValue + '\%3C/email%3E';
newPHPXML+='%3Cwebsite%3E' + xmlDoc.getElementsByTagName("website")[x].childNodes[0].nodeValue + '\%3C/website%3E';
newPHPXML+='%3C/user%3E';
}
newPHPXML+='%3Cuser%20username=%22' + document.register.username.value + '%22%3E';
newPHPXML+='%3Cname%3E' + document.register.name.value + '\%3C/name%3E';
newPHPXML+='%3Cage%3E' + document.register.age.value + '\%3C/age%3E';
newPHPXML+='%3Cpassword%3E' + encPass + '\%3C/password%3E';
newPHPXML+='%3Cemail%3E' + document.register.email.value + '\%3C/email%3E';
newPHPXML+='%3Cwebsite%3E' + document.register.website.value + '\%3C/website%3E';
newPHPXML+='%3C/user%3E';
newPHPXML+='%3C/excalo%3E';
alert('newPHPXML configured');
/////////////////////////////// AJAX Send the Data
function callback(serverData, serverStatus) { // Called automatically when we get data back from server
alert('Registration successfull!');
}
function ajaxRequest() {
var AJAX = null; // Initialize the AJAX variable.
if (window.XMLHttpRequest) { // Does this browser have an XMLHttpRequest object?
AJAX=new XMLHttpRequest(); // Yes -- initialize it.
} else { // No, try to initialize it IE style
AJAX=new ActiveXObject("Microsoft.XMLHTTP"); // Wheee, ActiveX, how do we format c: again?
} // End setup Ajax.
if (AJAX==null) { // If we couldn't initialize Ajax...
alert("Your browser doesn't support AJAX."); // Sorry msg.
return false // Return false, couldn't set up ajax
}
AJAX.onreadystatechange = function() { // When the browser has the request info..
if (AJAX.readyState==4 || AJAX.readyState=="complete") { // see if the complete flag is set.
callback(AJAX.responseText, AJAX.status); // Pass the response to our processing function
} // End Ajax readystate check.
}
var url='login-out.php?newxml=' + newPHPXML; // This is the URL we will call.
AJAX.open("GET", url, true); // Open the url this object was set-up with.
AJAX.send(null); // Send the request.
}
ajaxRequest();
}
addUser();
}
Here's my code so far...(still under construction) Thank you for your last post, I haven't tried it yet but it sounds like it will work.
PS: Basically my script reads an XML file, rewrites the existing users, and adds one. (its like a register thing) I have it URL encoded and stored in one var so I can send it with GET. I just realized the escape() func so later I'll simply use an escape() on it, instead of URL encoding it in the JS. THnx!