Out of project requirements, the application of ajaxfileupload. JS, one of jquery plug-ins, part of JS Code As follows:
$. Ajaxfileupload ({
URL: "uploadtemplte. aspx ",
Secureuri: false,
Fileelementid: "upfileinput ",
Datatype: "JSON ",
Success: function (data, status ){
If (data. Flag = "1 ")
{
$ ("# Divmsg" cmd.html ("
$ ("# loading_msg" ).html ("");
}< BR >},
error: function (data, status, E)
{< br> alert ("Upload Failed:" + E. tostring ();
}< BR >}) };
The submission page is uploadtemplte. aspx, mainly used to save the uploaded file. The returned data type is JSON. The main code on the page server is as follows:
Protected void page_load (Object sender, eventargs E)
{
Try
{
Httpfilecollection uploadfiles = request. Files; // sets of uploaded files
Httppostedfile thefile = uploadfiles [0]; // obtain and upload an Excel file
Thefile. saveas (tofile );
Response. write ("{flag: '1', MSG: 'file uploaded successfully', filename: '" + filename + "', orifilename: '"+ oname + "'}");
}
Catch
{
Response. Write ("{flag: '1', MSG: 'file upload failed', filename: '0', orifilename: '" + oname + "'}");
} Finally
{
Response. End ();
}
}
At first glance, it seems that there is no problem. The object error occurs during runtime. As JS debugging is not mastered, the problem cannot be found after the vs2005 breakpoint is called for half a day. Finally, a user can find the problem.
A demo made by ajaxfileupload. js. After careful comparison, I found that a sentence is missing.And its inconspicuous response. End (); rely on .... Dizzy...