Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello everyone,



I am pretty new to all this but I am trying to make a simple webpage with html and css, now I am in the point where I want to save some data taken from html form to xml (or JSON) file. I installed mongoose and I have a url for my files. I suppose I have to see a change in the file item.xml but this isn't happening. Any thoughts? Thank you in advance

The code I have is:

HTML
<!DOCTYPE html>
  <html>
  <head>

  <link rel="stylesheet" href="style.css">
  <script src="login.js"></script>
  <title>Login</title>
  </head>
  <body>
  <form id="loginform">
  <div>
  <p id="insertinfo">Type your info to log in your account:</p>
  <label for="Username">Username:</label>
  <input type="text" id="username" placeholder="Type your username"/>
  </div>
  <div>
  <label for="password">Type password:</label>
  <input type="text" id="password" placeholder="Type your password"/>
  </div>
  <div class="loginButton">
  <input type="submit" value="Log in" id="loginbutton" onClick = "callServer()" />
  </div>
  </body>
  </html>

and the javascript file:
JavaScript
function callServer(){
	
	
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	var xmlString =  "<profile>" + 
							"<username>" + escape(username) +"</username>" + 
							"<password>" + escape(password) +"</password>" +							
							"</profile>";
// Build the URL to connect to
var url = "http://localhost:8080/item.xml";
// Open a connection to the server
xmlHttp.open("POST", url, true);
// Tell the server you're sending it XML
xmlHttp.setRequestHeader("Content-Type", "text/xml");
// Set up a function for the server to run when it's done
xmlHttp.onreadystatechange = confirmUpdate;
// Send the request
xmlHttp.send(xmlString);

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900