Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bom dia galera..
Estou fazendo um select aninhado só que não estou tendo muita sorte com isso.
Fiz todo o código e não sei o que possa não estar funcionando.
Queria que alguém com mais experiência com asp clássico desse uma olhada no meu código e me disse onde eu errei, pois estou desde ontem batendo cabeça com ele.
Passo o download do arquivo AJAX
ESTÁ É A PÁGINA CALCULA_FRETE.ASP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--COMBO-->
<script type="text/javascript" src="../scripts/js/ajax.js"></script>
<script type="text/javascript">
function Ajax() {
var req;
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(ex) {
try {
req = new XMLHttpRequest();
} catch(exc) {
alert("Esse browser n�o tem recursos para uso do Ajax");
req = null;
}
}
}
return req;
}
function reflesh(){
var ajax = new Ajax();
ajax.open("POST", "calculo_frete_produtos.asp?cod="+document.form.tipo_subcategoria.value , true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.onreadystatechange = function() {
if(ajax.readyState == 4) {
if(ajax.status == 200) {
document.getElementById("div_select").innerHTML = ajax.responseText;
} else {
<!-- ajax.statusText) //-->
}
}
}
ajax.send("acao=reflesh");
delete ajax;
}
</script></head>
<body>
<!--CONTEÚDO-->
<div id="conteudo">
<!--COMBO-->
<%
Set TB = Server.CreateObject("ADODB.Recordset")
SQL = " Select a.ID_SUBCATEGORIAS, a.TXT_SUBCATEGORIA "_
& " from TBP_PRODUTOS_SUBCATEGORIAS a "_
& " inner join VW_PRODUTOS b on a.ID_SUBCATEGORIAS = b.ID_SUBCATEGORIAS and b.BIT_HABILITADO = 1 "_
& " and b.BIT_HABILITADO = 1 "_
& " where a.BIT_ACTIVE = 1 and a.ID_CATEGORIAS_PRINCIPAL = 14 "_
& " group by a.ID_SUBCATEGORIAS, a.TXT_SUBCATEGORIA order by a.TXT_SUBCATEGORIA "
TB.Open SQL, Conn, 1,3
'Response.Write(SQL)
%>
<select name="tipo_subcategoria" id="tipo_subcategoria" onchange="reflesh();">
<option value="">Selecione</option>
<%
if not TB.EOF then
Do while not TB.EOF
%>
<option value="<%=TB("ID_SUBCATEGORIAS")%>"><%=TB("TXT_SUBCATEGORIA")%></option>
<%
TB.MoveNext : Loop
end if : TB.Close
%>
</select>
<select name="tipo_produto" id="tipo_produto" class="formtext_livre">
<option value="">Selecione --</option>
<option value="">Aguardando selecionar um Produto</option>
</select>
<!--FIM COMBO-->
</div>
</div>
</body>
</html>
PÁGINA CALCULA_FRETE_PRODUTOS
<%
Set TB = Server.CreateObject("ADODB.Recordset")
SQL = " select a.ID_PRODUTO, a.TXT_PRODUTO, a.TXT_CATEGORIA, a.ID_CATEGORIAS, a.ID_SUBCATEGORIAS, a.TXT_SUBCATEGORIA "_
& " from VW_PRODUTOS a "_
& " where a.BIT_ACTIVE = 1 and a.BIT_ESGOTADO = 0 and a.BIT_HABILITADO = 1 and a.ID_SUBCATEGORIAS ='"&Request.QueryString("cod") &"' "
TB.Open SQL, Conn, 1,3
'Response.Write(SQL)
%>
<select name="tipo_produto" id="tipo_produto">
<option value="">Selecione</option>
<%AGRADEÇO A FORÇA!!!
E ai galera..
PARA QUEM ESTIVER PRECISANDO VOU PASSAR O CÓDIGO COM AS CORREÇÕES QUE FIZ...
AGORA TA FUNCIONANDO PERFEITO..
PAGINA QUE CHAMA O PRIMEIRO COMBO
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title><%=titLojaSite%></title>
<link href="../css/estilos.css" rel="stylesheet" type="text/css" />
<!--COMBO-->
<script type="text/javascript" src="../scripts/js/ajax.js"></script>
<script type="text/javascript">
function Ajax() {
var req;
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(ex) {
try {
req = new XMLHttpRequest();
} catch(exc) {
alert("Esse browser n�o tem recursos para uso do Ajax");
req = null;
}
}
}
return req;
}
function reflesh(){
var ajax = new Ajax();
ajax.open("POST", "calculo_frete_produtos.asp?cod="+document.getElementById("tipo_subcategoria").value , true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.onreadystatechange = function() {
if(ajax.readyState == 4) {
if(ajax.status == 200) {
document.getElementById("tipo_produto").innerHTML = ajax.responseText;
} else {
(ajax.statusText)
}
}
}
ajax.send("acao=reflesh");
delete ajax;
}
</script></head>
<body>
<div id="main">
<div id="pagina">
<!--CONTEÚDO-->
<div id="conteudo">
<!--COMBO-->
<%
Set TB = Server.CreateObject("ADODB.Recordset")
SQL = " Select a.ID_SUBCATEGORIAS, a.TXT_SUBCATEGORIA "_
& " from TBP_PRODUTOS_SUBCATEGORIAS a "_
& " inner join VW_PRODUTOS b on a.ID_SUBCATEGORIAS = b.ID_SUBCATEGORIAS and b.BIT_HABILITADO = 1 "_
& " and b.BIT_HABILITADO = 1 "_
& " where a.BIT_ACTIVE = 1 and a.ID_CATEGORIAS_PRINCIPAL = 14 "_
& " group by a.ID_SUBCATEGORIAS, a.TXT_SUBCATEGORIA order by a.TXT_SUBCATEGORIA "
TB.Open SQL, Conn, 1,3
'Response.Write(SQL)
%>
<select name="tipo_subcategoria" id="tipo_subcategoria" onchange="reflesh();">
<option value="">Selecione</option>
<%
if not TB.EOF then
Do while not TB.EOF
%>
<option value="<%=TB("ID_SUBCATEGORIAS")%>"><%=TB("TXT_SUBCATEGORIA")%></option>
<%
TB.MoveNext : Loop
end if : TB.Close
%>
</select>
<select name="tipo_produto" id="tipo_produto" class="formtext_livre">
<option value="">Selecione --</option>
<option value="">Aguardando selecionar um Produto</option>
</select>
<!--FIM COMBO-->
</div>
</body>
</html>
PAGINA QUE ATUALIZA O COMBO
<%
Set TB = Server.CreateObject("ADODB.Recordset")
SQL = " select a.ID_PRODUTO, a.TXT_PRODUTO, a.TXT_CATEGORIA, a.ID_CATEGORIAS, a.ID_SUBCATEGORIAS, a.TXT_SUBCATEGORIA "_
& " from VW_PRODUTOS a "_
& " where a.BIT_ACTIVE = 1 and a.BIT_ESGOTADO = 0 and a.BIT_HABILITADO = 1 and a.ID_SUBCATEGORIAS ='"&Request.QueryString("cod") &"' "
TB.Open SQL, Conn, 1,3
'Response.Write(SQL)
%>
<select name="tipo_produto" id="tipo_produto">
<option value="">Selecione</option>
<%CÓDIGO AJAX
function ajax() {
};
ajax.prototype.iniciar = function() {
try{
this.xmlhttp = new XMLHttpRequest();
}catch(ee){
try{
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
this.xmlhttp = false;
}
}
}
return true;
}
ajax.prototype.ocupado = function() {
estadoAtual = this.xmlhttp.readyState;
return (estadoAtual && (estadoAtual < 4));
}
ajax.prototype.processa = function() {
if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
return true;
}
}
ajax.prototype.enviar = function(url, metodo, modo) {
if (!this.xmlhttp) {
this.iniciar();
}
if (!this.ocupado()) {
if(metodo == "GET") {
this.xmlhttp.open("GET", url, modo);
this.xmlhttp.send(null);
} else {
this.xmlhttp.open("POST", url, modo);
this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
this.xmlhttp.setRequestHeader("Pragma", "no-cache");
this.xmlhttp.send(url);
}
if (this.processa) {
return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
}
}
return false;
}
DESDE JÁ AGRADEÇO E BOM PROVEITO DO CÓDIGO :)
Carregando comentários...