Ajax表单后不会发布与文件输入型表单、文件、Ajax

2023-09-10 19:57:10 作者:奔跑在路上

我有简单的形式,并与阿贾克斯张贴,但我不能够得到$ _FILES在PHP脚本

 <形式ID =submitForm方法=邮报是enctype =的multipart / form-data的>
     <输入类型=文件名称=文件/>
     <输入类型=文本名称=名称/>
    < /形式GT;
 

下面就是Ajax code,告诉我,我错了。

  $。阿贾克斯({
                网址:'< PHP的回声BASE_URL(); ?>的getter / addItemRow',
                键入:POST,
                数据:$('#submitForm')序列化()。
                背景:$('#表)
                })。完成(功能(数据){
                  这prePEND(数据);
                });
 

下面是php code线

 的print_r(后续代码var_dump($ _ FILES));
 
PHP代码合集21个邮箱2个问答23个ajax特效

这是返回空数组;

解决方案

 <脚本SRC =htt​​p://malsup.github.com/jquery.form.js> < / SCRIPT>


$(函数(){
    $('#submitForm)。当作ajaxForm(函数(结果){
                    $(#HiddenRowsa)隐藏()。
                    $('#表)prePEND(结果)。
                })。提交();
         });
 

所有我得到的答案都是一样的和右,这个简单的jQuery code,将工作,都在这里提供的链接,失踪.submit()函数在该当作ajaxForm的,因此所有谁正在寻找这类问题的人首先要在头上面的文件,然后写上code

"i have simple form and posting it with ajax, but i am not able to get the $_FILES in php script"

<form id="submitForm" method="post" enctype="multipart/form-data" >
     <input type="file" name="file"  />
     <input type="text" name="name" />
    </form>

below is ajax code,tell me where i am mistaken

$.ajax({
                url: '<?php echo base_url(); ?>getter/addItemRow',
                type:"POST",
                data:$('#submitForm').serialize(),
                context: $('#table')
                }).done(function(data) {
                  this.prepend(data);
                });

below is php code line

print_r(var_dump($_FILES));

this is returning empty array;

解决方案

<script src="http://malsup.github.com/jquery.form.js"></script> 


$(function() { 
    $('#submitForm').ajaxForm(function(result) {
                    $("#HiddenRowsa").hide();
                    $('#table').prepend(result);
                }).submit();
         });

all the answers that i got that were all same and RIGHT,this the simple jquery code that will work,all the links that are provided here, were missing .submit() function in the of the ajaxForm,so all the others who are looking for this kind of problem first include the above file in the head then write the above code