Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
jcfr

include

Recommended Posts

jcfr

boas pessoal...

tenho algumas bases de javascript mas so mesmo o essencial, ainda estou a aprender...

queria fazer algo similar ao include do php include "pagina.php";

tentei utilizar

document.getElementById('conteudo').innerHTML=('<script type="text/javascript" src="teste.php"></scr' + 'ipt>');

mas não funciona, o bojectivo seria alterar o include dentro de um span... e queria fazelo utilizando javascript para nao ter de carregar novamente a página toda... alguma ideia?

Share this post


Link to post
Share on other sites
IceBrain

Se queres carregar uma página HTML (gerada por PHP neste caso), tens que usar Ajax, ou seja, um método para pedir os conteúdos  a partir de Javascript.

Há duas formas: ou usas directamente os métodos dos browsers (aconselho-te a procurares por XMLHttpRequest) ou usas a biblioteca JQuery, e então o código é só:

$('#conteudo').load('teste.php');

http://api.jquery.com/load/


❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents

A list  of command line apps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.