Upload files based on jQuery Ajax, jqueryajax

Source: Internet
Author: User

Upload files based on jQuery Ajax, jqueryajax

This article provides examples of key code for File Upload Based on jQuery Ajax for your reference. The specific content is as follows:

JS Code:

// SAVE function btnAdd () {var formData = new FormData ($ ("# frm") [0]); $. ajax ({url: "/Admin/ContentManage/SaveEdit", type: "POST", data: formData, contentType: false, // if it is set to false, the default processing of formdata by jQuery is avoided. XMLHttpRequest correctly processes formdata. processData: false. // The correct Content-Type success is automatically added only when it is set to false: function (data) {if (data = "OK") {alert ("saved successfully"); $. iDialog ("close"); // refresh the parent page} else {alert ("failed to save:" + data );}}});}

ASP. net mvc background code:

// First, determine whether the path exists. If the Path does not exist, create the path string Path = path. combine (System. configuration. configurationManager. appSettings ["UploadsFiles"], folder + "/" + DateTime. now. toString ("yyyyMMdd") + "/"); string physicalPath = server. mapPath (path); if (! Directory. exists (physicalPath) {Directory. createDirectory (physicalPath);} HttpPostedFileBase file = request. files [0]; string newFileName = Guid. newGuid (). toString (). replace ("-", "") + Path. getExtension (file. fileName); string savePath = Path. combine (physicalPath, newFileName); file. saveAs (savePath); fileName = file. fileName; string url = Path. combine (path, newFileName); return url;

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • An example of a simple jQuery plug-in ajaxfileupload. js to implement ajax File Upload
  • JQuery plugin ajaxFileUpload implements asynchronous file upload
  • JQuery plug-in ajaxfileupload. js uploads files asynchronously to an instance.
  • JQuery asynchronous file upload plug-in ajaxFileUpload details
  • PHP uses the jQuery plug-in ajaxFileUpload to Implement Asynchronous file upload.

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.