I started my AJAX and wrote a simple test! (Js is as follows)
<! 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>
<Title> </title>
<Script type = "text/javascript">
Function btnOnclick (){
Var xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
If (! Xmlhttp ){
Alert ("An error occurred while creating xmlhttp! ");
Return false;
}
Xmlhttp. open ("POST", "1. ashx? Ts ", false );
Xmlhttp. onreadystatechange = function (){
If (xmlhttp. readyState = 4 ){
If (xmlhttp. status = 200 ){
Alert (xmlhttp. responseText );
Document. getElementById ("txtTime"). value = xmlhttp. responseText;
}
Else {
Alert ("error returned by AJAX server! ");
}
}
}
Xmlhttp. send ();
}
</Script>
</Head>
<Body>
<Input id = "txtTime" type = "text"/>
<Input id = "btnOK" type = "button" value = "click" onclick = "btnOnclick ()"/>
</Body>
</Html>
1. The ashx content is as follows!
<% @ WebHandler Language = "C #" class = "GetDate1" %>
Using System;
Using System. Web;
Using System. Web. Services;
[WebService]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
Public class GetDate1: IHttpHandler
{
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
Context. Response. Write (DateTime. Now. ToString ());
}
Public bool IsReusable
{
Get
{
Return false;
}
}
}
However, the system always prompts "AJAX server returns an error !", No error is found! Hope someone can give me some advice!