'FormData' is undefined in IE only

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.

Answers


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


Need Your Help

Load several templates from a single file

javascript angularjs

I have a project containing several sections. Each section (inside a dropdown item menu) requires specifics templates. I want group these templates in a file and cache them when the user make click...

How to compile/migrate a Visual Studio solution from a machine to another?

c++ visual-studio visual-c++ visual-studio-2013 windows-10

Recently I obtained a solution which has been created on another person's machine. I have been banging my head into the monitor in the past 2 days trying to fully migrate the solution to my machine...