Erro JavaScript no I.E. ("Erro em tempo de execução desconhecido")

6 respostas
M

Pessoal tenho um arquivo .js que carrega páginas via ajax em sistema de tabsheet. Porém quando vou carregar uma página no I.E. que tenha a tag dá o alerte com a mensagem “Erro em tempo de execução desconhecido”, isso apenas no IE, já no Firefox roda normalmente.

Alguém poderia analisar o arquivo ajaxtabs.js e ver o que pode estar errado ?

Obrigado.

AjaxTabs.JS

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadstatustext="<span class=red>Carregando, aguarde...</span>"

////NO NEED TO EDIT BELOW////////////////////////
var loadedobjects=""
var defaultcontentarray=new Object()
var bustcacheparameter=""

function ajaxpage(url, containerid, targetobj){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
		var ullist=targetobj.parentNode.parentNode.getElementsByTagName("li")
		for (var i=0; i<ullist.length; i++)
			ullist[i].className=""  //deselect all tabs
			targetobj.parentNode.className="selected"  //highlight currently clicked on tab
			if (url.indexOf("#default")!=-1){ //if simply show default content within container (verus fetch it via ajax)
				document.getElementById(containerid).innerHTML=defaultcontentarray[containerid]
				return
			}
			document.getElementById(containerid).innerHTML=loadstatustext
			page_request.onreadystatechange=function(){
			loadpage(page_request, containerid)
	}
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
		page_request.open('GET', url+bustcacheparameter, true)
		page_request.send(null)
	}

	function loadpage(page_request, containerid){
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
			document.getElementById(containerid).innerHTML = unescape(page_request.responseText.replace(/\+/g," "))
	}

	function loadobjs(revattribute){
		if (revattribute!=null && revattribute!=""){ //if "rev" attribute is defined (load external .js or .css files)
			var objectlist=revattribute.split(/\s*,\s*/) //split the files and store as array
			for (var i=0; i<objectlist.length; i++){
				var file=objectlist[i]
				var fileref=""
				if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
					if (file.indexOf(".js")!=-1){ //If object is a js file
						fileref=document.createElement('script')
						fileref.setAttribute("type","text/javascript");
						fileref.setAttribute("src", file);
					}
					else if (file.indexOf(".css")!=-1){ //If object is a css file
						fileref=document.createElement("link")
						fileref.setAttribute("rel", "stylesheet");
						fileref.setAttribute("type", "text/css");
						fileref.setAttribute("href", file);
					}
				}
				if (fileref!=""){
					document.getElementsByTagName("head").item(0).appendChild(fileref)
					loadedobjects+=file+" " //Remember this object as being already added to page
				}
			}
		}
	}

	function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
		var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
		if (thetab.getAttribute("rel")){
			ajaxpage(thetab.getAttribute("href"), thetab.getAttribute("rel"), thetab)
			loadobjs(thetab.getAttribute("rev"))
		}
	}

	function savedefaultcontent(contentid){// save default ajax tab content
		if (typeof defaultcontentarray[contentid]=="undefined") //if default content hasn't already been saved
			defaultcontentarray[contentid]=document.getElementById(contentid).innerHTML
	}

	function startajaxtabs(){
		for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
			var ulobj=document.getElementById(arguments[i])
			var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
			for (var x=0; x<ulist.length; x++){ //loop through each LI element
				var ulistlink=ulist[x].getElementsByTagName("a")[0]
				if (ulistlink.getAttribute("rel")){
					var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.host+"/")
					ulistlink.setAttribute("href", modifiedurl) //replace URL's root domain with dynamic root domain, for ajax security sake
					savedefaultcontent(ulistlink.getAttribute("rel")) //save default ajax tab content
					ulistlink.onclick=function(){
					ajaxpage(this.getAttribute("href"), this.getAttribute("rel"), this)
					loadobjs(this.getAttribute("rev"))
					return false
				}
				if (ulist[x].className=="selected"){
					ajaxpage(ulistlink.getAttribute("href"), ulistlink.getAttribute("rel"), ulistlink) //auto load currenly selected tab content
					loadobjs(ulistlink.getAttribute("rev")) //auto load any accompanying .js and .css files
				}
			}
		}
	}
}

6 Respostas

M

Ah, o I.E. está indicando que o erro está na linha:document.getElementById(containerid).innerHTML = unescape(page_request.responseText.replace(/\+/g," ")).

Algum expert em Ajax/Javascript por aqui para me ajudar pelo amor de Deus ?

Grato.

M

Pessoal descobri a causa do erro no I.E. !!!! agora falta descobrir a solução.

O erro ocorre quando a DIV que recebe a página chamada por ajax fica entre as tags

e a página que é chamada também tem as tags
. por exemplo:

<FORM ... >
         <table ...>
               <tr><td><input ...></tr></td>
               <tr><td>
                       <ul>    
                             <li><a href="profile.listaPerfis.logic" rel="ajaxcontentarea"><fmt:message key="aba_perfis"/></a></li>
                       </ul>
                       <DIV id="ajaxcontentarea"></DIV>
               </tr></td>
               <tr><td><input ...></tr></td>
         </table>
</FORM>

Por que ocorre isso no I.E ?? O que devo fazer para ele funcionar no I.E. ??

Grato.

L

Experimenta remover o IE e reinstalar.

D

estou com o mesmo problema

G

Estou com o mesmo problema

document.getElementById(div).innerHTML=page_request.responseText;

alguem pode dar um help??

G

RESOLVIDO:
Bom dia.
o IE 6.0, 7.0 e 8.0 não suportam innerHTML.
Solução, com prototype ele utiliza outro metodo de appendChild. Onde vc chama uma nova pagina e carrega ela no lugar do innerHTML.
veja um exemplo:

function carregaConteudo(){ var strUrl = 'pagina2.php'; var strMS = new Date().getTime(); try { var myAjax = new Ajax.Updater('conteudo',strUrl, { method : 'get', // parameters: pars, onLoading: mostrarLoading, onComplete: mostrarResposta }); } catch(error) { onComplete: mostrarResposta alert(error.descripton) alert(error.number) } }
Testado em IE, FF e Opera
É isso.
Grato

Criado 25 de outubro de 2007
Ultima resposta 13 de mai. de 2010
Respostas 6
Participantes 4