JQuery AJAX相当于表单的提交文件

时间:2022-11-24 14:50:31

I have a form, like this

我有一个表格,像这样

<form id="picuploadform" enctype="multipart/form-data" method="post" action="">

    <div class="row">
      <label for="fileToUpload">Select a File to Upload</label><br />
      <input type="file" name="fileToUpload" id="fileToUpload" /> 
     <input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
    </div>

    <div class="row" style="width:150px;">
   <input type="submit"  value="Upload" />
    </div>

  </form>

Which when I click the submit button I have PHP on this page to process it just fine. $_FILES for receiving file and $_POST for reading picssn that came with the hidden input. But due to problem with Jquery mobile I can't use submit or .submit() now. So I want to use

当我点击提交按钮时,我在这个页面上有PHP来处理它就好了。用于接收文件的$ _FILES和用于读取隐藏输入附带的picssn的$ _POST。但是由于Jquery mobile的问题,我现在无法使用submit或.submit()。所以我想用

$.post('myphpfile.php', {picssn:$('#picssn').value(), file: $('#fileToUpload').xxxxxxxxxxxxxxxxx  }); 

instead. But I have no idea how to grab the file out of that form and send it this way. Is there some method that can replace xxxxxxxxxxxxxx ? Thanks!

代替。但是我不知道如何从该表单中获取文件并以这种方式发送它。有什么方法可以取代xxxxxxxxxxxxxx吗?谢谢!

2 个解决方案

#1


0  

On your form element, you need to disable the ajax submit, and then fix your other code. Try this:

在表单元素上,您需要禁用ajax提交,然后修复其他代码。尝试这个:

<form id="picuploadform" enctype="multipart/form-data" method="post" action="#" data-ajax="false">

    <div class="row">
      <label for="fileToUpload">Select a File to Upload</label><br />
      <input type="file" name="fileToUpload" id="fileToUpload" /> 
     <input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
    </div>

    <div class="row" style="width:150px;">
   <input type="submit"  value="Upload" />
    </div>

  </form>

#2


0  

You cant upload directly via ajax. Check this perhaps: http://blueimp.github.com/jQuery-File-Upload/ or uploadify.com

你不能直接通过ajax上传。也许检查一下:http://blueimp.github.com/jQuery-File-Upload/或uploadify.com

#1


0  

On your form element, you need to disable the ajax submit, and then fix your other code. Try this:

在表单元素上,您需要禁用ajax提交,然后修复其他代码。尝试这个:

<form id="picuploadform" enctype="multipart/form-data" method="post" action="#" data-ajax="false">

    <div class="row">
      <label for="fileToUpload">Select a File to Upload</label><br />
      <input type="file" name="fileToUpload" id="fileToUpload" /> 
     <input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
    </div>

    <div class="row" style="width:150px;">
   <input type="submit"  value="Upload" />
    </div>

  </form>

#2


0  

You cant upload directly via ajax. Check this perhaps: http://blueimp.github.com/jQuery-File-Upload/ or uploadify.com

你不能直接通过ajax上传。也许检查一下:http://blueimp.github.com/jQuery-File-Upload/或uploadify.com