File upload +textarea questions submitted?

Source: Internet
Author: User
      
    $ ("#duty_add"). Click (function () {var root = $ ("P#root"). Text ();        var vals = $.trim ($ ("#content"). Val ());                if (vals! = ") {$.ajax ({type:" POST ", Url:root +"/duty/dutyadd ",                    Data: {' content ': Vals}, Success:function (data) {Console.log (file_value);                $ ("#result"). HTML (data);        }            });        }else{alert (' content cannot be null ');        }            });  $ ("#upload_file"). Change (function () {if ($ ("#upload_file"). val ()! = ") {var root = $ (" P#root "). Text (); Gets the path var Root2 = $ ("P#root2"). Text ();            Get path var formData = new FormData ($ ("#uploadForm") [0]);                  $.ajax ({url:root + "/duty/fileup", type: ' POST ', Data:formdata, Async:true, Cache:false, Contenttype:false, PROcessdata:false, Success:function (returndata) {File_value[returndata.name] = RET                                                              Urndata.url; $ ("#uploadForm"). Prepend (' + returndata.name + ' + ')
"); } }); }; });

An attachment upload is an AJAX asynchronous commit that generates a hyperlink from each other.

$("#uploadForm").prepend(''+ returndata.name + ''+"
");

But when textarea click Submit, then how to submit the content of the hyperlink?
If it is more than one upload file, how to submit the value of the upload file function return? How to get more convenient, is not my train of thought is wrong?
Think for a long time can't figure out how to deal with such?
Give me a clue, I want to try it.

Reply content:

    
    $ ("#duty_add"). Click (function () {var root = $ ("P#root"). Text ();        var vals = $.trim ($ ("#content"). Val ());                if (vals! = ") {$.ajax ({type:" POST ", Url:root +"/duty/dutyadd ",                    Data: {' content ': Vals}, Success:function (data) {Console.log (file_value);                $ ("#result"). HTML (data);        }            });        }else{alert (' content cannot be null ');        }            });  $ ("#upload_file"). Change (function () {if ($ ("#upload_file"). val ()! = ") {var root = $ (" P#root "). Text (); Gets the path var Root2 = $ ("P#root2"). Text ();            Get path var formData = new FormData ($ ("#uploadForm") [0]);                  $.ajax ({url:root + "/duty/fileup", type: ' POST ', Data:formdata, Async:true, Cache:false, Contenttype:false, PROcessdata:false, Success:function (returndata) {File_value[returndata.name] = RET                                                              Urndata.url; $ ("#uploadForm"). Prepend (' + returndata.name + ' + ')
"); } }); }; });

An attachment upload is an AJAX asynchronous commit that generates a hyperlink from each other.

$("#uploadForm").prepend(''+ returndata.name + ''+"
");

But when textarea click Submit, then how to submit the content of the hyperlink?
If it is more than one upload file, how to submit the value of the upload file function return? How to get more convenient, is not my train of thought is wrong?
Think for a long time can't figure out how to deal with such?
Give me a clue, I want to try it.

You have saved the uploaded results in this variable when the file was uploaded. file_value
Then in your submission textarea , in data :{'content':vals}, this place, you file_value can also pass it to the backstage.
Like what:data:{'content':vals, 'files':file_value},

You send the code, there is no file_value place for this variable definition, so here is the assumption that your two at the time of the ajax trigger, you can access the variable, and the same one.

If the content is to be submitted, it should be placed in input

  • 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.