I. Page code<! 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> Qin ShiChuan </title>
<Script src = "qsc. js/Qin. Ajax. js" type = "text/javascript"> </script>
<Script>
Function test (){
MyAjax ("Handler. ashx", "frm1", {}, function (data ){
Alert (data );
});
}
</Script>
</Head>
<Body>
<Form id = "frm1">
<Input type = "file" name = "filedata"/> <! -- File Upload -->
<Input type = "text" name = "username"/> <input id = "Button1" type = "button" onclick = "test (); "value =" button "/>
</Form>
</Body>
</Html>
We can submit Custom Data in
MyAjax (action, formID, data, callback) // data in the format of {age: 6, address: "Chongqing"}
Background code
<% @ WebHandler Language = "C #" Class = "Handler" %>
Using System;
Using System. Web;
Public class Handler: IHttpHandler {
Public void ProcessRequest (HttpContext context ){
Var name = context. Request ["username"];
Var age = context. Request ["age"];
Var address = context. Request ["address"];
Var file = context. Request. Files [0]. FileName;
Var ret = name + "" + age + "" + address + "" + file;
WriteForm (context, ret );
}
Public bool IsReusable {
Get {
Return false;
}
}
Public void WriteForm (HttpContext context, string str)
{
String method = context. Request ["callback"];
String hs = "<script> void" + method + "('" + str + "'); </script> ";
Context. Response. Write (hs );
Context. Response. Flush ();
Context. Response. Close ();
Context. Response. End ();
}
}
Note:
Public void WriteForm (HttpContext context, string str) This method does not have to be modified and can be customized.
Running Effect
Download source code:/Files/humble/WebSite1.zip (Leave a message for download)