Compatible with ie and ff asynchronous form submission and refreshing submission
Htm 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/Webpage effects"> </script>
<Script>
Function test (){
Myajax ("handler. ashx", "frm1", {age: 16, address: "Chongqing"}, function (data ){
Alert (data );
});
}
</Script>
</Head>
<Body>
<Form id = "frm1">
<Input type = "file" name = "filedata"/>
<Input type = "text" name = "username"/> <input id = "button1" type = "button" onclick = "test (); "value =" button "/>
</Form>
</Body>
</Html>
Handler. ashx File
<% @ 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 ();
}
}