Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 防止;新建FormData();在IE中,不包括没有名称属性的输入元素_Jquery_Html_Internet Explorer - Fatal编程技术网

Jquery 防止;新建FormData();在IE中,不包括没有名称属性的输入元素

Jquery 防止;新建FormData();在IE中,不包括没有名称属性的输入元素,jquery,html,internet-explorer,Jquery,Html,Internet Explorer,我正在尝试使用jQueryAjax将formData发送到服务器。。。 这是我的html文件: <form id="my_form"> <div> <p>first name :</p> <input type="text" name="first_name" value="Bill"> </div> <div> <p>seco

我正在尝试使用jQueryAjax将formData发送到服务器。。。 这是我的html文件:

 <form id="my_form">
    <div>
        <p>first name :</p>
        <input type="text" name="first_name" value="Bill">
    </div>
    <div>
        <p>second name :</p>
        <input type="text" name="second_name" value="Gates">
    </div>
    <div>
        <p>should not send to the server :</p>
        <input type="text" value="haha">
    </div>
</form>
下面是我的问题,当我在IE11中运行此功能时,请求负载如下图所示,服务器说它是一个坏的内容体,因此请求失败:

如果我在Chrome中运行,它运行良好,请求负载是:
我知道,如果我从Dom中删除最后一个没有“name”属性的输入,它甚至在IE中也会工作,那么,如果我保留最后一个输入,有没有办法让它在IE中工作?非常感谢…

您可以克隆原始的
表单
,删除最后一个
输入
元素或没有
名称
属性的
输入
元素,然后将
表单数据
参数设置为克隆的
表单
,其中不包括最后一个
输入

var clone = $("#my_form").clone();
clone.find("input:last").remove();
var formData = new FormData(clone[0]);

据我所知,这确实是一个IE bug。一个快速的解决方法是在创建
FormData
对象之前禁用未命名的输入

var $form = $("#my_form");

// Disable "input" elements (input, select, textarea) that do not have 
// a name attribute and were not disabled beforehand, saving a reference to them
var $unnamedInputs = $form.find(":input:not([name]):not(:disabled)").prop('disabled', true);

var formData = new FormData($form[0]);

// Re-enable the inputs that we had just disabled
$unnamedInputs.prop('disabled', false);


嗯,我认为IE不应该这么做(因为看起来……关了)。IE是以本机IE11运行还是正在仿真?另外,这是本机FormData还是自定义的?@user2864740它作为本机IE 11运行。
var $form = $("#my_form");

// Disable "input" elements (input, select, textarea) that do not have 
// a name attribute and were not disabled beforehand, saving a reference to them
var $unnamedInputs = $form.find(":input:not([name]):not(:disabled)").prop('disabled', true);

var formData = new FormData($form[0]);

// Re-enable the inputs that we had just disabled
$unnamedInputs.prop('disabled', false);