Chamar HTML em vez de criar html em JS

11 respostas
zicky23

Boa tarde, tenho esse seguinte cód.

function createWindowWithBoundary2(parentElmId) { if( parentElmId != null ) { var iconUrl = 'http://mail.google.com/favicon.ico'; if( parentElmId == 'my_boundary_panel3' ) { iconUrl = 'https://picasaweb.google.com/favicon.ico'; } /* $("#"+parentElmId).window({ //icon: iconUrl, title: "Cadastro de contribuintes", content: "<div style='padding:10px; font-weight:bold;'>"+ "NOME CONTRIBUINTE: <input type='text' name='nomecontribuinte'>" +"</div>", checkBoundary: true, width: 600, height: 300, //minWidth: 600, //maxWidth: 400, //maxHeight: 300, //minHeight: 200, x: 400, y: 100, onSelect: function(wnd) { // a callback function while user select the window log('select'); }, onUnselect: function(wnd) { // a callback function while window unselected log('unelect'); } });*/ } else { $.window({ //icon: 'http://www.fstoke.me/favicon.ico', title: "Cadastrar novo Contribuinte", content: //"<style type=text/css>@import url(css/estilo.css)</style>"+ "<div>"+ "<table style='font-size:0.8em;font-family: verdana;list-style:none;border:0px solid #ccc'>"+ "<tr>"+ "<td style='padding:8px'></td>"+ "</tr><tr>"+ "<td>Nome:</td><td><input type=text name=nomecontrib></td><td>Sobrenome:</td><td><input type=text name=sobrenome></td>"+ //"</tr><tr>"+ //"<td>Servico:</td><td colspan=4><input type=text name=serv size=59></td>"+ "</tr><tr>"+ "<td>Endereco:</td><td><input type=text name=end></td><td>Numero:</td><td><input type=text name=number></td>"+ //"</tr>"+ "</tr><tr>"+ "<td>Fone:</td><td><input type=text name=fone></td>"+ "</tr>"+ "<tr>"+ "<td style='padding:8px'></td>"+ "</tr><tr>"+ "<td align='right' colspan=4><input type='button' value='Cadastrar'></td></tr>"+ "</table>"+ "</div>", checkBoundary: true, x: 400, width: 500, height: 200, y: 100, z: 2100 }); } }

em JS. até ai tudo bem, mas gostaria que ao invez de ter que digitar o html dentro de “aspas” gostaria de chamar um html externo, tem como?

obrigado

11 Respostas

kiko_lp_St_jimmy

Já tentou utilizar a função ajax do Jquery ?

http://api.jquery.com/category/ajax/

Otimização - SEO

CharlesAlves

Ou então dá uma olhada em DOM seria bem mais simples que escrever o html assim e mais correto.

davidbuzatto

Você pode:
1 - Usar um iframe (hoje em dia é “feio”)
2 - Usar frames (mais feio ainda)
3 - Usar a função load do jQuery para obter os dados desejados e inserir em algum container, que pode ser uma div.

[]'s

rafaduka

Assim:

$('#<sua-div>').load('galeria/treco.html');
zicky23

Boa tarde.

Será que alguem pode dar um exemplo.

[img]http://www.vielmond.net/0102.png[/img]

gostaria que ao clicar em Serviço, ele abra um jframe como o exemplo acima, mas ao invez de usar o cód dentro do CONTENT como abaixo:

function createWindowWithBoundary(parentElmId) {
	if( parentElmId != null ) {
		var iconUrl = 'http://mail.google.com/favicon.ico';
		if( parentElmId == 'my_boundary_panel2' ) {
			iconUrl = 'https://picasaweb.google.com/favicon.ico';
		}
	} else {
            
		$.window({
			//icon: 'http://www.fstoke.me/favicon.ico',
			title: "Cadastrar novo Servico",
			content:  // AKI NO LUGAR DESSE CONTENT, GOSTARIA DE USAR ALGO PARA CHAMAR UM HTML  FORMATADO.
                            "<div>"+
                            "<table style='font-size:0.8em;font-family: verdana;list-style:none;border:0px solid #ccc'>"+
                            "<tr>"+
                            "<td style='padding:8px'></td>"+
                            "</tr><tr>"+
                            "<td>Nome:</td><td><input type=text name=nomecontrib></td><td>Sobrenome:</td><td><input type=text name=sobrenome></td>"+
                            "</tr><tr>"+
                            "<td>Servico:</td><td colspan=4><input type=text name=serv size=59></td>"+
                            "</tr><tr>"+
                            "<td>Endereco:</td><td><input type=text name=end></td><td>Numero:</td><td><input type=text name=number></td>"+
                            "</tr>"+
                            "<tr>"+
                            "<td style='padding:8px'></td>"+
                            "</tr><tr>"+
                            "<td align='right' colspan=4><input type='button' value='Cadastrar'></td></tr>"+
                            "</table>"+
                            "</div>",
			checkBoundary: true,
			x: 400,
                        width: 500,
                        height: 200,
			y: 100,
			z: 2100
		}); 
	}
}

gostaria de usar um html separado, já tentei usar o load como vcs deram a dica, mas nao abre nada dai..

valeu desde já

zicky23

Se alguem tiver alguma dica me avisa, por enquanto vou fazendo dessa maneira mesmo, colocando o cód html dentro do content:

obrigado

F

pq não tentou o load do jquery?

zicky23

Cara tentei sim, mas ai nem abre a janela “Cadastrar novo Servico”. Não acontece nada. ve o cód ai:

$.window({ $(window).load('cadastro_servico.html'); //icon: 'http://www.fstoke.me/favicon.ico', title: "Cadastrar novo Servico", /* content: // AKI NO LUGAR DESSE CONTENT, GOSTARIA DE USAR ALGO PARA CHAMAR UM HTML JÁ FORMATADO. "<div>"+ "<table style='font-size:0.8em;font-family: verdana;list-style:none;border:0px solid #ccc'>"+ "<tr>"+ "<td style='padding:8px'></td>"+ "</tr><tr>"+ "<td>Nome:</td><td><input type=text name=nomecontrib></td><td>Sobrenome:</td><td><input type=text name=sobrenome></td>"+ "</tr><tr>"+ "<td>Servico:</td><td colspan=4><input type=text name=serv size=59></td>"+ "</tr><tr>"+ "<td>Endereco:</td><td><input type=text name=end></td><td>Numero:</td><td><input type=text name=number></td>"+ "</tr>"+ "<tr>"+ "<td style='padding:8px'></td>"+ "</tr><tr>"+ "<td align='right' colspan=4><input type='button' value='Cadastrar'></td></tr>"+ "</table>"+ "</div>", checkBoundary: true, x: 400, width: 500, height: 200, y: 100, z: 2100 */ });

F

1 min

F

tenta assim oh…

$.ajax({
		  url: 'teste.html',		  
		  success: function(data){
			//data AQUI VAI SER O SEU HTML ai você ver como pegar e jogar ele no seu content
		  },
		  dataType: 'html'
		});
zicky23

ok vou tentar!

valeu

Criado 29 de janeiro de 2012
Ultima resposta 1 de fev. de 2012
Respostas 11
Participantes 6