表单提交没有网址刷新

时间:2013-11-28 12:45:07

标签: jquery forms

我的代码在这里

<form action="/custom/moustache/save_image" method="post" enctype="multipart/form-data">
        <input type="file" name="image_data" id="imageLoader"/>
        <input type="submit" value="Submit"/>
      </form>

请有人帮助我如何在没有刷新URL的情况下提交我的文件。

1 个答案:

答案 0 :(得分:0)

HTML 5: Use Blueimp fileupload plugin

HTML 4: 使用iframe并提交

<iframe id="uploadTrg" name="uploadTrg" height="0" width="0" frameborder="0" scrolling="yes"></iframe>

<form id="myForm" 
    action="http://example.com/file-upload-service" method="post"    
    enctype="multipart/form-data"  target="uploadTrg">

    File: <input type="file" name="file">
    <input type="submit" value="Submit" id="submitBtn"/>

</form>

然后

$("iframe").load(function(){

alert("The file is uploaded");


$.post('http://example.com/file-upload- 
     service?do=getLastFile',null,function(attachment){

     $("#ajaxResultTest").append("<h4>" + attachment.name + ":" +
                                     attachment.id "</h4>");

 },'json');
});