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);
}

 

Link to comment
Share on other sites

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!!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.