all groups > dotnet xml > april 2006 >
You're in the

dotnet xml

group:

xmlhttprequest



xmlhttprequest vimalathithan NO[at]SPAM gmail.com
4/27/2006 9:58:23 AM
dotnet xml: Can some body write a simple example for xmlhttprequest ??
I am only able to find the client side coding ,but not the server side
coding.... it would be nice to have a complete code ( both client side
and server side .)

thanks
Vimal
Re: xmlhttprequest Vimal
4/27/2006 10:32:52 AM
Hi Martin,
I refered http://www.xmlhttprequest.org/

And in that there a code like the follwoing thing.... in client side
.....
----------------------
request.open("GET", "myServerPage.aspx", true);
request.send();
----------------------

what i like to know is that what and how should i write the
myserverPage.aspx page (for the above example)

-- Vimal
Re: xmlhttprequest Vimal
4/27/2006 10:51:52 AM
why i am asking for the example is i have a doubt.........if i call
like this(myServerPage.aspx) it will execute all the page code right ?
.......
instead i want to execute a function which will return a xml document
as of now ....
so that i can further increase the functionality to get the data from a
data base and send that back to the clide as a XML document.

............. How can i differentiate the code in the aspx page to
identify whether the request is as "Autopost back request" or"
XMLHttprequest "?

---Vimal
Re: xmlhttprequest Martin Honnen
4/27/2006 7:18:15 PM


[quoted text, click to view]

Well it depends on what you want to do, with ASP.NET there are various
possibilities, if someone does a HTTP POST request with an XML document
in the request body then one way with .NET to read that is e.g.
XmlDocument requestXML = new XmlDocument();
requestXML.Load(Request.InputStream);
That way you get an XML DOM XmlDocument of the POSTed XML. You can use
any API .NET provides however on that InputStream, e.g. using an
Xml(Text)Reader is possible as well.

If you want to send XML back to the client then again there are lots of
ways to do that, you could for instance use an XmlTextWriter on
Response.Output e.g.
Response.ContentType = "application/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteElementString("god", "Xibo");
xmlWriter.WriteEndDocument();

--

Martin Honnen --- MVP XML
Re: xmlhttprequest Martin Honnen
4/27/2006 7:49:00 PM


[quoted text, click to view]


[quoted text, click to view]

Well author that aspx page the same way you would author other aspx
pages, the client-side code makes an HTTP GET request to that URL with
the myServerPage.aspx page without passing anything in the querystring
nor with passing anything in the request body.
So there is no data passed in that myServerPage.aspx could process, it
simply needs to create a HTTP response.
Noone but you can tell what to do exactly in that page as it simply
depends on your needs, whether you want to return an XML document (see
my earlier answer on how to return that on the fly using XmlTextWriter),
whether you want to return some text, whether you want to return some
JSON data, whether you want to return some HTML.

--

Martin Honnen --- MVP XML
Re: xmlhttprequest Martin Honnen
4/27/2006 8:08:09 PM


[quoted text, click to view]


[quoted text, click to view]

Here is an example of a simple ASP.NET page sending back some XML
generated with XmlTextWriter

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
void Page_Load() {
Response.ContentType = "application/xml";
XmlTextWriter xmlWriter = new XmlTextWriter(Response.Output);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("gods");
xmlWriter.WriteElementString("god", "Kibo");
xmlWriter.WriteElementString("god", "Xibo");
xmlWriter.WriteEndDocument();
}
</script>

You might also want to look into ASP.NET HTTP handlers as the proper
tool to process HTTP requests without the (possible overhead of the)
ASP.NET page model:
<http://samples.gotdotnet.com/quickstart/aspplus/doc/httphandlers.aspx>

[quoted text, click to view]

The same as with any request processed in an aspx page
if (IsPostBack) {

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button