Ajax表单后不会发布与文件输入型 [英] Ajax form post not posting input type with file

查看:112
本文介绍了Ajax表单后不会发布与文件输入型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的形式,并与阿贾克斯张贴,但我不能够得到$ _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));
 

这是返回空数组;

解决方案

 <脚本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

这篇关于Ajax表单后不会发布与文件输入型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆