'FormData' undefined only in IE

I have a problem when I need to send data as the contents of 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 everything works fine above in all other browsers, I get the following error in IE9.

 SCRIPT5009: 'FormData' is undefined view.js, line 57 character 9 

line 57 is var data = new FormData();

Ive heard that FormData() is a browser-dependent function and is not related to the jquery library, and in IE it is missing.

The reason I use the above method is because I have to transfer data in application/x-www-form-urlencoded format.

I can not change the encoding on the server side (since this is due to the iphone application in the appstore).

All I can do is try from the client side.

Does anyone have a solution for this?

ps: I am using backbone.js.

+8
javascript jquery form-data
source share
1 answer

Try entering the 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 helps you.

+3
source share

All Articles