Jump to content

[SOLVED] Ajax Problems with Internet Explorer on Looping a collection by class name


giba

Recommended Posts

Hi there!

I am issuing a problem with IE that I can't solve it, because in all other browsers it work perfectly.

I did a simple script that gets the HTML from an element by its class name, send it via ajax and gets the result from a .php file which contains a Google script for translation, the problem however is that only Internet explorer returns nothing.

 

The question is:

 

How can I send the HTML of an element and get it back on IE based on a loop that cicles AJAX requests?

 

Follows de script I used:

 

The code for getting the element by its class name:

 


document.getElementsByClassName = function(class_name) {
    var docList = this.all || this.getElementsByTagName('*');
    var matchArray = new Array();

    
    var re = new RegExp("(?:^|\\s)"+class_name+"(?:\\s|$)");
    for (var i = 0; i < docList.length; i++) {
        if (re.test(docList[i].className) ) {
            matchArray[matchArray.length] = docList[i];
        }
    }

return matchArray;
}

 

The code for looping through the elements with the class "translate":

 

				

var trans = document.getElementsByClassName('translate');
for ( var i = 0; i < trans.length; i++) {  
    t = trans[i];
    translate(t,'translate.php?string='+escape(t.innerHTML.replace(/[\r\n]+/g, ""))+'&l=<?=$_GET['l'];?>&c='+Math.random())
}

 

And the code for AJAX:

 


function translate(target, url)
{
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert("Your browser does not support XMLHTTP!");
        }
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4) {
            target.innerHTML = xmlhttp.responseText;
   //alert(xmlhttp.responseText);
        }
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

 

After dealing a lot with GET requests I found that IE limits the value of 500 charactes per value of a parameter in the Query String, so I dealt with this fragmenting my code in more peaces.

Not the best choise, but works!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.