Jump to content
Fórum Script Brasil
  • 0

Ajax não exibe alert


Snoopy1
 Share

Question

Fiz um código em ajax que carrega a página text.html e criei dois alerts o primeiro para exibir o código html completo do text.html e o segundo para exibir apenas o texto "Hello World." que está na class example na html do text.html, obtenho êxito no primeiro alert, no entanto o segundo alert exibe uma caixa vazia.. Venho pedir ajuda de vocês para me ajudarem como puderem.

index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	
	<title>Load page</title>
 
	<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
 
	<script type="text/javascript">
	if(window.XMLHttpRequest){
	variavelhtttp = new XMLHttpRequest();
	}else{
	alert("Withouth Ajax!");
	}
	</script>
 
</head>
 
<body>
 
	<button type="button" onclick="loadDoc()">Go</button>
 
	<script type="text/javascript">
		function loadDoc(){
			variavelhtttp= new XMLHttpRequest();
			variavelhtttp.open("GET","text.html",false);
			variavelhtttp.send();
			var y = variavelhtttp.responseText;
			alert(y);
			alert(  $( ".example" ).text() );
		 }
	</script>
 
</body>
</html>

text.html

<html>
<head>
	<title></title>
</head>
<body>
	<div class="example">Hello World.</div>
</body>
</html>

 

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...