FormData对象未通过jQuery AJAX调用提交 [英] FormData Object not submitting via jQuery AJAX call

查看:92
本文介绍了FormData对象未通过jQuery AJAX调用提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此脚本从表单获取所有值,以便为Ajax请求做准备:

I'm using this script to get all values from a form, in order to prepare it for an ajax request:

function saveDataAjax(){
    var fd = new FormData();
    var inputs = document.getElementsByTagName('input');
    for(i=0;i<inputs.length;i++) {
        fd.append(inputs[i].name, inputs[i].value);
    }
    $.ajax({
        url: '/edit.php',
        data: fd,
        type: 'POST',
        dataType: 'html',
        success: function(data){
            alert(data);
        }
    });
}

但是我从jQuery中得到了Type error,并且如果我警告fd['inputname'],我将变得不确定,所以我想我在某处一定做错了...

However I'm getting a Type error from jQuery, and if I alert fd['inputname'] I get undefined, so I guess I must be doing something wrong somewhere...

Firefox调试器告诉我:NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object @ http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js:2

Firefox debuggers tells me this: NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object @ http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js:2

推荐答案

将以下内容添加到AJAX调用中:

Add the following to the AJAX call:

 processData: false,
 contentType: false,

它看起来像:

  $.ajax({
       url: '/edit.php',
       data: fd,
       type: 'POST',
       processData: false,  //Add this
       contentType: false, //Add this
       dataType: 'html',              
       success: function(data){
           alert(data);
       }
   });

这篇关于FormData对象未通过jQuery AJAX调用提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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