1
I want to upload a list of a div
, from one page to another (both on my server). I know that for this there is the function jquery $('#content').load('paginaexemplo.htm' '#lista')
, but I’d like to know how I do it with javascript pure.
1
I want to upload a list of a div
, from one page to another (both on my server). I know that for this there is the function jquery $('#content').load('paginaexemplo.htm' '#lista')
, but I’d like to know how I do it with javascript pure.
-1
You can do it this way with Xmlhttprequest:
var http = new XMLHttpRequest();
var url_ = "pagina.php"; // página de onde virá a div
http.open("GET", url_, true);
http.onreadystatechange = function(){
if(http.readyState == 4){
var html = http.responseText;
// converte o retorno em elementos HTML
html = new DOMParser().parseFromString(html, "text/html");
document.getElementById('id_da_div_que_irá_receber').innerHTML = html.getElementById('id_da_div_que_de_onde_virá').innerHTML.trim();
}
}
http.send(null);
Browser other questions tagged javascript html5
You are not signed in. Login or sign up in order to post.
Good morning, this code worked very well in firefox and even in explorer, but in CHROME it does not run at all. I already tried to know what could be but found no solution,have some hint of what might be the problem?
– Luan Rodrigues
Now I figured out the problem,for security reasons Chrome requires the page to be with some protocol,in case,I hosted my pages on a test host and with https protocol,and it worked, anyway vlw
– Luan Rodrigues
Oh yes, Chrome locks if it’s not HTTP...
– Sam
Hello Luan! When online, please give a call. I wanted to ask a question. Thanks!
– Sam
'Cause no sam,?
– Luan Rodrigues
Obg Luan, already solved. Thanks!
– Sam