Hi A few things wrong in your code.
1)
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
;this is no problem, no need to change
2) When you are posting directly get it from the Request object, not from query string
string
xpto = Page.Request.QueryString["texto"];
..this is wrong. According to your code in the other.aspx it should be string xpto=Request["content"];
once you written to the xml then read it and use
response.write(the xml content)
. So what you have written here will be collected through the response text.
3)this assignment
texto = xmlhttp.responseText;
is wrong. It should be
texto.value = xmlhttp.responseText;
.
So here is the corrected version of your code except the xml write and read part..
In the aspx..
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
function alterar() {
var texto = document.getElementById('texto');
alert(texto.value);
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
texto.value = xmlhttp.responseText;
alert("success");
}
else {
// alert("reach here");
alert(xmlhttp.readyState + " " + xmlhttp.status);
}
}
var data = "file=info.txt&content=" + texto.value;
xmlhttp.open("POST", "Default2.aspx", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(data);
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div id="myDiv"><h2>Here is the content readed from XML File</h2></div>
<input type='text' id='texto' /><br />
<input type='button' onclick='alterar()' value='testar aqui' />
</asp:Content>
in the Default2.aspx code behind in my example ..
protected void Page_Load(object sender, EventArgs e)
{
string content = Request["content"];
Response.Write("data received " + content);
}
By pressing button you can see the response received from the default2.aspx. I think you can handle the xml reading and writing part. If any questions post comment here.