Jquery+ajax simple implementation of File upload method _jquery

Source: Internet
Author: User
Tags file upload

The example of this paper describes the simple implementation of Jquery+ajax file upload method. Share to everyone for your reference, specific as follows:

You can submit a form via Ajax without refreshing the page. The main methods used are $ ("#formID"). Ajaxsubmit () method .

1, to introduce JS plug-in

Attachments to download: jquery.form.js

2, page code:

<script src= "Project/js/jquery.form.js" type= "Text/javascript" ></script>
<script src= "project/" Js/fileload.js "type=" Text/javascript "></script>
<script type=" Text/javascript ">
$ ( Document). Ready (function () {
createhtml ($ ("#str"))
</script>
<tr>
<td> photo </td>
<td>
<div id= "str" >
</ div>
<p style= "display:none;" id= "Timgurl" ></p>
<p style= "color:red" id= "Timgok" > </p>
</td>
</tr>
<script src= "~/project/js/jquery.form.js" type= "Text/javascript" ></script>
<script src= "~/project/js/fileload.js" type= "Text/javascript" ></script>

Fileload.js:

function Fileloadon () {
$ ("#msg"). HTML ("");
$ ("#_fileForm"). Submit (function () {
$ ("#_fileForm"). Ajaxsubmit ({
type: "Post",
URL: "/ 201410carvideoadmin/home/uploadhelper ",
success:function (data1) {
$ (' #timgUrl '). HTML (data1);
var reg = new RegExp (' "," G ");
var imageUrl = $ (' #timgUrl '). Text (). Replace (Reg, "");
$ (' #backImgUrl '). attr ("src", imageUrl);
if ($ (' #timgUrl '). HTML ()!= null) {
$ (' #timgok '). html ("File upload succeeded"),
else {
$ (' #timgok '). html ("File upload failed") ;
}
,
error:function (msg) {
alert ("File upload Failed");}
)
; return false;
});
$ ("#_fileForm"). Submit ();


Controller Code:

[HttpPost]
Public ActionResult Uploadhelper ()
{
//start uploading
string imageUrl = string. Empty;
Qf. WebGamePlatform.Reference.FileUploadService service = new QF. WebGamePlatform.Reference.FileUploadService ();
var fileresult = service. Picupload (Request.files[0]);
if (Fileresult.code = = 0)
{
imageUrl = fileResult.Data.RawImageUrl;
}
Return Json (IMAGEURL, jsonrequestbehavior.allowget);


More interested readers of jquery-related content can view the site: The summary of AJAX usage in jquery, the summary of jquery switching effects and techniques, the summary of jquery drag-and-drop effects and techniques, the summary of jquery extension techniques, jquery Common Classic Effects Summary "jquery animation and special effects usage Summary", "jquery selector usage Summary" and "jquery common Plug-ins and Usage summary"

I hope this article will help you with the jquery program design.

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.