Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Pedroalves

[Resolvido] Problema no ajax

Recommended Posts

o meu ajax não esta a funcionar e não sei pk

var HttpReq = null;
 var dest_combo = null;

 function ajaxComboBox(url, comboBox){
	// alert('dentro');
  	 dest_combo = comboBox;
    var indice = document.getElementById('codcategoria').selectedIndex;
    var sigla = document.getElementById('codcategoria').options[indice].getAttribute('value');
    url = url + '?codcategoria=' + sigla;
	alert(url);
    if (document.getElementById) { //Verifica se o Browser suporta DHTML.
        if (window.XMLHttpRequest) {
            HttpReq = new XMLHttpRequest();
            HttpReq.onreadystatechange = XMLHttpRequestChange;
            HttpReq.open("GET", url, true);
            HttpReq.send(null);
        } else if (window.ActiveXObject) {
            HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            if (HttpReq) {
                HttpReq.onreadystatechange = XMLHttpRequestChange;
                HttpReq.open("GET", url, true);
                HttpReq.send();
            }
        }
    }
 }

 function XMLHttpRequestChange() {
	 alert('ola maria');
    //if (HttpReq.readyState == 4 && HttpReq.status == 200){
        var result = HttpReq.responseXML;
        var tabela_materiais = result.getElementsByTagName("material");
		alert(materiais);
        document.getElementById('dest_combo').innerHTML = "";
        for (var i = 0; i < materiais.length; i++) {
            new_opcao = create_opcao(materiais[i]);
            document.getElementById('dest_combo').appendChild(new_opcao);
       }
 //   }else alert("erro");
 }

 function create_opcao(material) { 
    var new_opcao = document.createElement("option"); 
    var texto = document.createTextNode(material.childNodes[0].data); 
    new_opcao.setAttribute("value",material.getAttribute("codmaterial")); 
    new_opcao.appendChild(texto); //Adiciona o texto a OPTION.
    return new_opcao; // Retorna a nova OPTION.
 }

Compartilhar este post


Link para o post
Compartilhar em outros sites

simplesmente o ajax não funciona

na segunda combo box devia aparecer o material e não aparece nada

 

afinal aparece um erro mas so me aparece se usar o internet explore

o erro é

Detalhes do erro da página Web

 

Mensagem: 'document.getElementById(...)' é nulo ou não é um objecto

Linha: 34

Caráct: 9

Código: 0

URL: http://localhost/labgest1/01.js

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigo você deve usar onload, pois a requisição não está esperando a página carregar Imagem Postada

 

O erro quer dizer que ele não achou o elemento

document.getElementById('codcategoria')
por que ele não existe na pagina ou a pagina ainda não esta carregada

 

 

Imagem Postada Atenciosamente Silverfox

Compartilhar este post


Link para o post
Compartilhar em outros sites

e como eu ponho a carregar

segue-se a pagina listarmaterial

<?php require_once('Connections/labgestconect.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "falhou.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
     header("Content-type: text/xml; charset=ISO-8859-1");
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
  ?>
 

 <materiais>
 <?php
   $result = mysql_query("SELECT * FROM tabela_material WHERE 
               codmaterial = '{$_GET['codcategoria']}' ORDER BY material")
    or die("Query invalida: " . mysql_error());

    while ($row = mysql_fetch_assoc($result)) {
       // printf("<nome id=\"%d\">%s</nome>\n", $row['codmaterial'],$row['material']);
	   echo "<nome id=\"".$row['codmaterial']."\">".$row['material']."</nome>";
    }

    mysql_close($link);
 ?>
</materiais>
e a pagina

<?php require_once('Connections/labgestconect.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "Templates/index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "1";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "falhou.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_labgestconect, $labgestconect);
$query_Recordset1 = "SELECT * FROM tabela_material";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $labgestconect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

mysql_select_db($database_labgestconect, $labgestconect);
$query_Recordset2 = "SELECT * FROM tabela_categotria";
$Recordset2 = mysql_query($query_Recordset2, $labgestconect) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?>
<!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"><!-- InstanceBegin template="/Templates/template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>LABGEST</title>
<script type="text/javascript" src="01.js"></script>

<!-- InstanceEndEditable -->
<style type="text/css">
<!--
body {
	background-color: #FFFFFF;
}
.style2 {font-family: "Aardvark Cafe"}
.style3 {font-family: "Estrangelo Edessa"}
.style5 {font-family: "Estrangelo Edessa"; font-size: 16px; }
-->
</style><!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript" src="stmenu.js"></script></head>

<body>
<table width="1000" height="44" border="0">
  <tr>
    <td height="5" colspan="2" align="left" valign="top" bgcolor="#FFFFFF"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1000" height="170">
      <param name="movie" value="aa1.swf" />
      <param name="quality" value="high" />
      <embed src="aa1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1000" height="170"></embed>
    </object></td>
    <td width="277" valign="top" bgcolor="#FFFFFF"><p align="center"><img src="logoestgsefs.jpg" width="104" height="46" /></p>
    <p><span class="style3"> </span></p>
    <p> </p>
    <p align="left"><span class="style5"><a href="<?php echo $logoutAction ?>"><img src="qx.png" width="51" height="61" border="0" /></a></span></p></td>
  </tr>
  <tr>
    <td height="5" colspan="3"> </td>
  </tr>
  <tr>
    <td width="202" height="400" align="left" valign="top" bgcolor="#FFFFFF">
<a href="http://www.dhtml-menu-builder.com"  style="display:none;visibility:hidden;">Javascript DHTML Drop Down Menu Powered by dhtml-menu-builder.com</a>
<script type="text/javascript">
<!--
stm_bm(["menu295c",900,"","blank.gif",0,"","",0,0,250,0,1000,1,0,0,"","",0,0,1,2,"hand","hand","",1,25],this);
stm_bp("p0",[1,4,0,0,4,2,8,7,100,"",-2,"",-2,50,0,0,"#999999","transparent","",3,0,0,"#000000"]);
stm_ai("p0i0",[0,"Home","","",-1,-1,0,"admin_home.php","_self","","","icon_81[1].gif","icon_81[3].gif",8,8,0,"","",0,0,0,0,1,"#FFFFFF",0,"#FFD602",0,"","",3,3,0,0,"#E6EFF9","#000000","#666666","#000000","bold 8pt Verdana","bold 8pt Verdana",0,0,"","","","",0,0,0]);
stm_ai("p0i1",[6,1,"#999999","",-1,-1,0]);
stm_aix("p0i2","p0i0",[0,"Requisição","","",-1,-1,0,"","_self","","","icon_81[1].gif","icon_81[1].gif",8,8,0,"arrow_r.gif","arrow_r.gif",7,7]);
stm_bp("p1",[1,2,0,0,2,2,8,0,100,"",-2,"",-2,50,0,0,"#999999","transparent","",3,1,1,"#999999"]);
stm_aix("p1i0","p0i0",[0,"Gerir requisição","","",-1,-1,0,"admin_gerir_requisicao.php","_self","","","icon_81[1].gif","icon_81[1].gif",8,8,0,"","",0,0,0,0,1,"#FFFFFF",0,"#FFD602",0,"","",3,3,0,0,"#999999"],80,0);
stm_aix("p1i1","p0i1",[]);
stm_aix("p1i2","p1i0",[0,"Devolução","","",-1,-1,0,"admin_devolucao.php"],80,0);
stm_ep();
stm_aix("p0i3","p0i1",[]);
stm_aix("p0i4","p0i2",[0,"Pesquisar"]);
stm_bpx("p2","p1",[]);
stm_aix("p2i0","p1i0",[0,"Pesquisar material","","",-1,-1,0,"admin_pesquizar_material.php"],80,0);
stm_aix("p2i1","p0i1",[]);
stm_aix("p2i2","p2i0",[0,"Pesquisar equipamento","","",-1,-1,0,"admin_pesquizar_equipamento.php"],80,0);
stm_ep();
stm_aix("p0i5","p0i1",[]);
stm_aix("p0i6","p0i2",[0,"Material"]);
stm_bpx("p3","p1",[]);
stm_aix("p3i0","p2i0",[0,"Gerir material","","",-1,-1,0,"admin_gerir_material.php"],110,0);
stm_aix("p3i1","p0i1",[]);
stm_aix("p3i2","p2i0",[0,"Categoria material","","",-1,-1,0,"admin_categoria_material.php"],110,0);
stm_ep();
stm_aix("p0i7","p0i1",[]);
stm_aix("p0i8","p0i6",[0,"Equipamento"]);
stm_bpx("p4","p1",[]);
stm_aix("p4i0","p2i0",[0,"Gerir equipamento","","",-1,-1,0,"admin_gerir_equipamento.php"],110,0);
stm_aix("p4i1","p0i1",[]);
stm_aix("p4i2","p2i0",[0,"Tipo equipamento","","",-1,-1,0,"admin_tipo_equipamento.php"],110,0);
stm_aix("p4i3","p0i1",[]);
stm_aix("p4i4","p2i0",[0,"Marca equipamento","","",-1,-1,0,"admin_marca_equipamento.php"],110,0);
stm_ep();
stm_aix("p0i9","p0i1",[]);
stm_aix("p0i10","p0i6",[0,"Utilizador"]);
stm_bpx("p5","p1",[]);
stm_aix("p5i0","p2i0",[0,"Gerir utilizador","","",-1,-1,0,"admin_gerir_utilizador.php"],120,0);
stm_aix("p5i1","p0i1",[]);
stm_aix("p5i2","p2i0",[0,"Gerir curso utilizador","","",-1,-1,0,"admin_curso_utilizador.php"],120,0);
stm_ep();
stm_aix("p0i11","p0i1",[]);
stm_aix("p0i12","p0i6",[0,"Laboratório","","",-1,-1,0,"admin_laboratorio.php","_self","","","icon_81[1].gif","icon_81[1].gif",8,8,0,"","",0,0]);
stm_aix("p0i13","p0i1",[]);
stm_aix("p0i14","p0i12",[0,"Fornecedor","","",-1,-1,0,"admin_fornecedor.php"]);
stm_aix("p0i15","p0i1",[]);
stm_aix("p0i16","p0i12",[0,"Créditos","","",-1,-1,0,"admin_credito.php"]);
stm_ep();
stm_em();
//-->
</script>	</td>
    <td width="752" valign="top" bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="EditRegion1" -->     
      <title><title></title>
      <h2>MATERIAL </h2>
 <form>
 <select name="codcategoria" id="codcategoria" onChange="ajaxComboBox('listadematerial.php','codmaterial');">
   <option selected value="NDA">-- TIPO --</option>
   <?php
do {  
?>
   <option value="<?php echo $row_Recordset2['codcategoria']?>"><?php echo $row_Recordset2['categoria']?></option>
   <?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  $rows = mysql_num_rows($Recordset2);
  if($rows > 0) {
      mysql_data_seek($Recordset2, 0);
	  $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  }
?>
 </select>
 <select name="codmaterial" id="codmaterial">
    <option>-- MATERIAL --</option>
 </select>
 </form>
    <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="EditRegion5" -->
    <p> </p>
    <p> </p>
    <!-- InstanceEndEditable --></td>
    <td bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="EditRegion8" --><!-- InstanceEndEditable --></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>
<?php include ('listadematerial.php');?>

ainda estou com problemas no ajax no topico esta o codigo em php

alguem me pode ajudar a ver a onde esta o erro

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.