Jump to content
Fórum Script Brasil
  • 0

Incluir conteúdo html em div, problemas como o Chrome


Derme
 Share

Question

Olá, uso um script ajax para incluir o conteúdo de um arquivo html em uma div.

Funciona normalmente no IE e Fire Fox, mas não teve jeito de funcionar no Chrome.

arquivo ajax.js

function GetXMLHttp() {
var xmlhttp=false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
try //Google Chrome
{
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",file,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML.documentElement;
}
catch(e)
{       
xmlhttp = false;
}
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

var xmlRequest = GetXMLHttp();

function mostra_conetudo(valor){
var url = valor;

xmlRequest.onreadystatechange = mudancaEstado;
xmlRequest.open("GET",url,true);
xmlRequest.send(null);

if (xmlRequest.readyState == 1) {
document.getElementById("inclui_conteudo").innerHTML = "carregando...";
}

return url;
}

function mudancaEstado(){
if (xmlRequest.readyState == 4){
document.getElementById("inclui_conteudo").innerHTML = xmlRequest.responseText;
}
}
Pagina index.html
<html>
<head>
    <title>Untitled</title>
    &lt;script language="javascript" src="ajax.js"></script>
</head>

<body>
<a href="#" onclick="mostra_conetudo('conteudo.html')" class="lmenu">Que somos</a>

<div id="inclui_conteudo" class="conetudo"></div>


</body>
</html>
Página de conteúdo a ser incluído conteudo.html
<p>
Apenas um teste
</p>

Alguém sabe como resolver?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

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.

 Share



  • Forum Statistics

    • Total Topics
      150.9k
    • Total Posts
      648.7k
×
×
  • Create New...