suarezst
asked on
Importing xml document in javascript and posting it to a url using an html webform
I need to import an xml file in order do a positing to a url. I am using xmlhttp request. The only problem I am having is that I need to create an html page where the user is able to browse the xml file and execute the posting on-click of the "posting" button.
I have imported the file already but I do not know how to link it to the file that the user has browsed and to the click of the button.
I have imported the file already but I do not know how to link it to the file that the user has browsed and to the click of the button.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)// code for IE7, Firefox, Opera, etc.
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)// code for IE6, IE5
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=loadXML();
xmlhttp.open("POST","http://yoursite.com/sample.xml",FALSE);
xmlhttp.send();
alert(xmlhttp.ResponseText);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
function loadXML()
{
var xmlDoc;
if (window.ActiveXObject)//IE
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)//FF
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load("xmlorders.xml");
}
</script>
<tittle> <br> Post an Order </br> </tittle>
</head>
<body>
<form id="form1" runat="server">
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
</div>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.