'FormData'仅在IE中未定义 [英] 'FormData' is undefined in IE only
问题描述
我有一个问题,我需要将数据发布为内容类型 application / x-www-form-urlencoded
。
I have a problem where i need to post the data as content-type application/x-www-form-urlencoded
.
var inputData = {cId:"444",pageNo:"1",latitude:"49.153236",longitude:"12.040905"};
var data = new FormData();
data.append('data', JSON.stringify(inputData));
this.model.save(data, {
data: data,
processData: false,
cache: false,
contentType: false,
success: function (model, resultData) {
$.get(App.baseUrl + 'templates/all-offers-view.html', function (data) {
template = _.template(data, {
data: resultData
});
that.$el.html(template);
}, 'html');
},
error: function (error) {
console.log("Error");
return false;
}
});
虽然以上在所有其他浏览器中都能正常工作,但我在IE9中收到以下错误。
While the above works fine in all other browsers, I am getting the following error in IE9.
SCRIPT5009: 'FormData' is undefined
view.js, line 57 character 9
第57行 var data = new FormData();
我听说 FormData()
是一个与浏览器相关的函数,它与jquery库无关,而在IE中则缺少它。
Ive heard FormData()
is a browser dependant function and its not related to jquery library and that in IE its missing.
我使用上述方法的原因是因为我必须在 application / x-www-form-urlencoded $中传递数据c $ c>格式。
The reason why i am using the above method is because i have to pass data in application/x-www-form-urlencoded
format.
我无法更改服务器端编码(因为它与appstore中的iphone应用程序链接)。
I cannot change the server side coding(as this is linked with an iphone app in appstore).
我所能做的只是尝试与客户端。
All i can do is try out with the client-side.
有没有人有这方面的解决方案?
Does anyone have a solution for this?
p.s:我正在使用backbone.js。
p.s : I am using backbone.js.
推荐答案
尝试以下代码:
if(typeof FormData == "undefined"){
var data = [];
data.push('data', JSON.stringify(inputData));
}
else{
var data = new FormData();
data.append('data', JSON.stringify(inputData));
}
希望这可以帮到你
这篇关于'FormData'仅在IE中未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!