Funky Dude
Funky Dude

Reputation: 3967

IE7 Ajax out of memory error

The script I am working on makes ajax call and it works fine on Firefox, chrome and IE8+. But on IE7, I am getting an out of memory error. The memory gets up to 120MB. I am using jQuery 1.8.3. The error also happens in jQuery 1.9 and 1.7.

the source:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: 'data.asmx/GetChildren',
    data: '{parent:"program","child":"office","id":' + this.Item_id + '}',
    dataType: 'json',
    success: function (r) {
        var data = r.d.data;
    }
});

this is the profile i get for IE7:

edit: updated with source edit: finally had time to go through the problem again. turned out to be a simple looping problem. not jQuery ajax's fault.

Upvotes: 4

Views: 1553

Answers (6)

Louis Ricci
Louis Ricci

Reputation: 21086

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: 'data.asmx/GetChildren',
    data: '{parent:"program","child":"office","id":' + this.Item_id + '}',
    dataType: 'text',
    success: function (r) {
        var data = (eval("[" + r + "]")[0]).d.data;
    }
});
  • Changed dataType to "text".
  • Used eval("[" + textJson + "]")[0] to get the object data.
    • If it still fails replace the "var data = ..." line with "var data = r;" and report if that fails also.

Upvotes: 0

MarmiK
MarmiK

Reputation: 5775

IF number of children are more, then the value returned to the var data will be more.

The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data. source Microsoft

So size is not an issue, but the character if exceeds then it is a problem. :)

Upvotes: 1

ncubica
ncubica

Reputation: 8485

Have you try to send a JSON.stringify instead of an Object, and in the server side decode?

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify

Upvotes: 0

nicholasnet
nicholasnet

Reputation: 2277

As per jQuery docs you can pass plain object so I would suggest to use object instead. Also can you please try to use Id like this and see if it makes any difference.

var id = this.Item_id; //
$.ajax
({
    type: "POST",
    url: 'data.asmx/GetChildren',
    data: {"parent":"program","child":"office","id": id},
    dataType: 'json',
    success: function (r) 
    {
        //Please use console.log(r) and see what is coming back here
    }
});

or simply

var id = this.Item_id; //
$.post("data.asmx/GetChildren", 
{
    "parent":"program",
    "child":"office",
    "id": id
}, function(r)
{
    //console.log(r);
},"json");

Upvotes: 0

Sanjeev Rai
Sanjeev Rai

Reputation: 6982

This problem can occur if virtual memory has been disabled.
To enable virtual memory, follow these steps:

Click the Start button, point to Settings, and then click Control Panel. Double-click the System icon. On the Performance tab, click Virtual Memory. Click the "Let Windows manage my virtual memory settings (recommended)" option. Or, if you must use your own virtual memory settings, allow as much space as possible for the maximum size. Click OK.

Upvotes: 0

Anderson Pimentel
Anderson Pimentel

Reputation: 5767

Don't know if it has something to do with your problem, but there are two things making your data an invalid JSON.

parent must be enclosed in quotation marks, just as the id value (you are only closing and reopening the string).

So, it should be like this:

$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: 'data.asmx/GetChildren',
        data: '{"parent":"program","child":"office","id":"' + this.Item_id + '"}',
        dataType: 'json',
        success: function (r) {
            var data = r.d.data;
        }
});

Upvotes: 0

Related Questions