问题
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;
}
});
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
line 57 being var data = new FormData();
Ive heard FormData()
is a browser dependant function and its not related to jquery library and that in IE its missing.
The reason why i am using the above method is because i have to pass data in application/x-www-form-urlencoded
format.
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 : I am using backbone.js.
回答1:
Try below code:
if(typeof FormData == "undefined"){
var data = [];
data.push('data', JSON.stringify(inputData));
}
else{
var data = new FormData();
data.append('data', JSON.stringify(inputData));
}
Hope this help you
来源:https://stackoverflow.com/questions/19486597/formdata-is-undefined-in-ie-only