Hi,
s.*******@symax.nl wrote:
Hi Steve,
thanks for the reply, but is developing a webservice for such a small
function not a little overkill. Of course I can combine AJAX and ATLAS.
Just a simple function for writing to the cache using an AJAX dll and
for controls use ATLAS.
The simplest implementation of AJAX in .NET is using ASHX Custom
HttpHandlers. It's very simple: In your web site or web application
project, Add New Item / Generic handler.
Then, in the code behind, implement the methods (Studio 2005 gives you a
template).
From the client, use JavaScript and XmlHttpRequest to send the request
and read the response. There are many tutorial online.
Example for a simple asynchronous request:
var oHttp = null;
if ( window.XMLHttpRequest )
{
oHttp = new window.XMLHttpRequest();
}
else
{
if ( window.ActiveXObject )
{
oHttp = new window.ActiveXObject( "Microsoft.XMLHTTP" );
}
else
{
throw "UNSUPPORTED PLATFORM";
}
}
if ( !oHttp )
{
throw "Cannot create XmlHttpRequest";
}
var strQuery = "?param1=value1¶m2=value2";
oHttp.open( "GET",
"myHandler.ashx" + strQuery,
true ); // true = async, false = sync
oHttp.onreadystatechange = function()
{
if ( oHttp.readyState == 4 )
{
oHttp = null;
fnCallback( oHttp );
}
}
oHttp.send( null );
Code behind:
In ProcessRequest, use the "context" parameter to extract the
QueryString, and then you can process according to the parameters.
For the Response, if you want to send XML code back, make sure to set
context.Response.ContentType = "text/xml; charset=utf-8";
To save an XML document to the response, use
docResponse.Save(
new XmlTextWriter( context.Response.OutputStream,
context.Request.ContentEncoding ) );
In the JavaScript, the XML code will be available in oHttp.responseXML.
The response is also available in plain text in oHttp.responseText. Also
check the oHttp.status, which contains status like 200 (OK), 500 (Server
error), etc...
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering:
http://www.galasoft-LB.ch
PhotoAlbum:
http://www.galasoft-LB.ch/pictures
Support children in Calcutta:
http://www.calcutta-espoir.ch