. NET instances (pseudo-asynchronous form submission, implementation of Brushless new forms (including files) submission) compatible with IE Firefox Based on LGPL open source declined to reprint

Source: Internet
Author: User
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)

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.