jQuery/Ajax IE7 - Long requests fail

1

I have a problem with IE7 regarding an ajax call that is made by jQuery.load function.

Basically the request works in cases where the URL string is not too long, but as soon as the URL gets very large it fails. Doing some debugging on the Ajax call I found this error:

URL: <blanked out security reasons but it's very long>
Content Type: 
Headers size (bytes): 0
Data size (bytes): 0
Total size (bytes): 0
Transferred data size (bytes): 0
Cached data: No
Error result: 0x800c0005
Error constant: INET_E_RESOURCE_NOT_FOUND
Error description: The server or proxy was not found
Extended error result: 0x7a
Extended error description: The data area passed to a system call is too small.

As you can see, it looks like nothing is being sent. Now this only happens on IE7 but not other browsers, with IE8 there is a small delay but still works. The same request works fine when the URL string is relatively small.

Now I need this working on IE7 for compatibility reasons, and I cannot find workarounds for this.

The actual AJAX call is like this:

$("ID").load("url?lotsofparams",callbac func(){}); 

"lotsofparams" can vary, sometimes being small or very large. It's when the string is very large that I get the above error for IE7 only.

javascript
jquery
ajax
asked on Stack Overflow Jun 8, 2010 by iQ. • edited Jan 9, 2018 by halfer

3 Answers

4

Don't put the query string parameters into the the url.

The second parameter of .load() is made just for that. Should be:

$("ID").load("url", {
    foo:     "bar",
    morefoo: "morebar"
},callbac func(){}); 

or you can use $.post()

$.post("url", {
    foo:     "bar",
    morefoo: "morebar"
}, function(data){
   alert(data);
});

Since the .load() will internally use a "POST" request when parsing an object, you might consider to replace it with $.get() if you require a "GET" request.

answered on Stack Overflow Jun 8, 2010 by jAndy • edited Jun 8, 2010 by jAndy
4

since load uses HTTP Get method, there is limit to the size of the url, which is 4KB as far as I know. So instead of GET, use $.ajax with HTTP Post option. Post has no limit.

use the following code.

$.ajax({
                url: url,
                type: "POST",
                async: true,
                data: {name1: value1, name2: value2, ...}, // put your data.
                success: function(data, textStatus) {
                 $("ID").html(data);

               }
       });
answered on Stack Overflow Jun 8, 2010 by dotcoder
0

I ran into this same problem. I had been sending everything via the URL (long querystring) and it was failing. I found out the key was to send the data in its own parameter (dataparms, in this example) which is just the querystring section of the URL.

$.ajax({type: "POST", url: URL, data: dataparams, dataType: "html", async:false});

answered on Stack Overflow Jan 18, 2013 by cf_dev

User contributions licensed under CC BY-SA 3.0