1

I am working on async load (using XMLHttpRequest .readystate & .responseText) of product table contents on pagination or filter changing. Funtions I wrote work perfectly but on local only. On apache/ngnix server-side it returns bad request. Please help.

function loadContent(link) {

    var http = createRequestObject();
    if( http ) {

        http.open('load', link);
        http.onreadystatechange = function () {

            if(http.readyState == 4) {

                var div = document.createElement('div');
                div.innerHTML = http.responseText;
                var all = div.getElementsByTagName('div');

                for (var i = 0, len = all.length; i < len; i++) {

                   if (all[i] && all[i].getAttribute('id') == 'to-ajax') {

                      var deep = all[i].getElementsByClassName('product-layout col-lg-4');
                      $('.load').before(deep);

                   }
                }
            }
        }

        http.send(null);

    } else {

        document.location = link;

    }
}

function createRequestObject() {
    try { return new XMLHttpRequest() }
    catch(e) {
        try { return new ActiveXObject('Msxml2.XMLHTTP') }
        catch(e) {

            try { return new ActiveXObject('Microsoft.XMLHTTP') }
            catch(e) { return null; }
        }
    }
}

Error warning refers to this line of code ~ } http.send(null);

It seems that problem is on .onreadystatechange function, but have no idea how to test it to define what an exact issue is.

buzz8year
  • 304
  • 4
  • 13
  • I've tried to rewrite funtion to get rid of responseText (merely changed responseText to responseXML) as it seemed to be a potential reason of error. Didn't help – buzz8year Nov 27 '15 at 09:18

1 Answers1

1

The first argument to open needs to be a string containing an HTTP request method. "load" is not an HTTP request method. Examples include "GET" and "POST". The invalid HTTP is likely causing your server to respond with the Bad Request error.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Solved it a moment before ur answer - and this is 100% right one! Thanks a lot mate! Would upvote u but have too low reputation, just signed up, sorry. – buzz8year Nov 27 '15 at 10:05