jQuery iframe file upload

前端 未结 5 768
栀梦
栀梦 2020-11-28 07:52

Im building a file upload with jQuery, but Im getting a jQuery error trying to set the attributes of the form:

$(document).ready(function () {
    $(\"#forms         


        
5条回答
  •  心在旅途
    2020-11-28 08:12

    You know instead of fetching the same item multiple times, why not just reuse it:

    var form = $('#theuploadform');
    form.attr("action", "/ajax/user.asmx/Upload");
    form.attr("method", "post");
    // and so on
    

    What kind of error are you having? can you post it?

    UPDATE

    Since you cannot set the attribute yourself here is a work around:

    Put the form in an iframe, and attach an onchange event to the input button. when the user select a file, you trigger the necessary code to upload the file (submit), then the parent window can close the iframe.

提交回复
热议问题