Js+ajax method of obtaining file size _javascript tips

Source: Internet
Author: User

The example in this article describes the Js+ajax method for obtaining file size. Share to everyone for your reference, specific as follows:

As the name suggests, through JS and Ajax to get the size of uploaded files, before uploading can have a judge, the upload of the file has control, because JS control file size (JS get file size) Some problems, specific everyone try to know, here to tidy up the Ajax to obtain file size method, more useful , and then debug the process, there have been c:/fakepath/errors, but also the solution listed below, for your reference

Less nonsense, the code is as follows

JS is as follows:

<script language= "Jscript" >
function Chksize () {
  var tickettype = "Oil";
  var File1=document.getelementbyid ("txtfile");
  var v = file1.value;
  File1.select ();
  var Realpath = Document.selection.createRange (). text;
  var input = "<Record><Type>TicketLoanResult</Type><TicketType>" + Realpath + "</tickettype ></Record> ";
  var objxmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
  Objxmlhttp.open ("POST", "xmlhttppost.aspx", false);
  Objxmlhttp.send (input);
  var returnxml = Objxmlhttp.responsetext;
  if (returnxml!=null)
  {
   returnxml=parseint (returnxml/1024/1024);
  }
  alert (returnxml); 
  return false; 
}
</script>

Background C # code:

Public partial class XMLHttpPost:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {try
   {XmlDocument xmldocumenet = new XmlDocument ();
   Xmldocumenet.load (Request.inputstream); String type = Xmldocumenet.selectsinglenode ("Descendant::type").
   InnerText; String returnmessage = String.
   Empty; Switch (type.
     Trim ()) {case "Ticketloanresult": ReturnMessage = Getticketloanresult (xmldocumenet);
    Break
   Default:break;
   } Response.ContentType = "Text/xml";
  Response.Write (ReturnMessage); catch (Exception exceptional) {///If there is a bug return error information (XML format) string errormessage = "<Error>" + exceptional.
   Message + "</Error>";
   Response.ContentType = "Text/xml";
  Response.Write (errormessage);
  finally {Response.End (); } private String Getticketloanresult (XmlDocument input) {XmlNode item = input.
  selectSingleNode ("Descendant::tickettype"); String TicketType = Item.
  Innertext.trim (); FileSTREAM stream = new FileStream (Tickettype,filemode.open); return stream.
 Length.tostring ();

 }
}

Full instance code click here to download the site.

I hope this article will help you with JavaScript programming.

Related Article

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.