Jump to content
Fórum Script Brasil
  • 0

(Resolvido) problema com onreadystatechange no internet explorer


matheus.labanca

Question

Boa tarde.

estou com um problema em um cod onde o metodo onreadystatechange não funciona no IE.

Fala que não foi implementado.

alguém pode me ajudar. abaixo o cod

document.write(unescape("%3Cscript src='js/marcaPalavra.js' type='text/javascript'%3E%3C/script%3E"));

blog = {

    id_blog : 1,
    ajaxObject : null,
    words : new Array(), // Keywords
    isIE : true,
    
    //Montando objeto XMLHttpRequest
    getHTTPObject: function() {
        try {
            // Firefox, Opera, Safari
            console.log("firefox, chrome");
            blog.isIE = false;
            return new XMLHttpRequest();
        }
        catch (e) {
            // Internet Explorer
            try    {
                console.log("IE 1");
                blog.isIE = true;
                return new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    console.log("IE 2");
                    blog.isIE = true;
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                    alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
    },
        
    //chama o php que pega as palavras do banco
    sendIdBlog : function(){

        blog.ajaxObject = blog.getHTTPObject();

        if (blog.ajaxObject != null)
        {
            
            blog.ajaxObject.open("GET", "testephp.php?blog="+blog.id_blog, false);
            blog.ajaxObject.send(null);
            blog.ajaxObject.onreadystatechange = 
                 ( blog.isIE )
                ? blog.setWords        //recebe o resultado vindo do php IE
                : blog.setWords();    //recebe o resultado vindo do php outros navegadores
        }
        
        blog.ajaxObject = null;
     
    },
    
    // Recebendo as palavras
    setWords: function(){
        
        var json_string = '';
        if (blog.ajaxObject.readyState == 4)
        {
            if(blog.ajaxObject.status == 200) {
                json_string = blog.ajaxObject.responseText;
                blog.words = eval(json_string);
                console.log(blog.words);
            }
        }
    },    

    //passa o array de palavras a serem grifadas
    loadWords: function() {
        blog.sendIdBlog();
        return blog.words;
    }    
}

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Cara valeu a ajuda, apesar de não querer usar uma biblioteca pronta achei melhor usar a prototype, ai deu certo, mas obrigado.

Segue o cod pra alguém que tiver o mesmo problema.

blog = {

    id_blog : 1,
    words : new Array(), // Keywords
    url : "testephp.php?blog=",        
    
    //chama o php que pega as palavras do banco
    sendIdBlog : function(){    
        var myAjax = new Ajax.Request( blog.url + blog.id_blog, { method: 'get', asynchronous: false, onComplete: blog.setWords });
    },
    
    // Recebendo as palavras
    setWords: function(ajaxObject){
        
        var json_string = '';
        json_string = ajaxObject.responseText;
        blog.words = eval(json_string);    
            
    },    

    //passa o array de palavras a serem grifadas
    loadWords: function() {
        blog.sendIdBlog();
        return blog.words;
    }    
}

Edited by matheus.labanca
Link to comment
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...