admin管理员组

文章数量:1295859

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.

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.

Share Improve this question asked Oct 21, 2013 at 5:04 Roy M JRoy M J 6,9487 gold badges53 silver badges79 bronze badges 2
  • 3 The patibility table at MDN indicates you might have issues with more than IE. There is also a link for how to submit the form data without the formData API. – RobG Commented Oct 21, 2013 at 5:18
  • :(.. that is very bad... ill try out the fix... – Roy M J Commented Oct 21, 2013 at 6:12
Add a ment  | 

1 Answer 1

Reset to default 3

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

本文标签: javascript39FormData39 is undefined in IE onlyStack Overflow