Ir para conteúdo

POWERED BY:

Arquivado

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

xxabxx

Requisição Ajax e php (html em pasta diferente)

Recommended Posts

Tenho uma pagina HTML que chama um arquivos JS que este faz requisição a um arquivo PHP e traz os resultados da busca.

 

Estão funcionando!

Mas eu gostaria

Que o HTML estivesse no C da minha maquina e o PHP no diretorio do Wamp que seria o meu ip "192.168.173.59".

 

Mesmo colocando o endereço ip/nomearquivo.php ele dá erro.

Consigo fazer colocando o endereço de ip, mas o HTML tem que estar em algum diretório do Wamp.

 

 

HTML

<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript" src="http://192.168.173.59/ajax.js"></script>
        <div id="Container">
            <h1>Agenda de Contatos utilizando AJAX</h1>
            <hr/>
            <h2>Pesquisar Contato:</h2>
            <div id="Pesquisar">
                Infome o nome: 
                <input type="text" name="txtnome" id="txtnome"/> 
                <input type="button" name="btnPesquisar" value="Pesquisar" onclick="getDados();"/>
            </div>
            <hr/>
            <h2>Resultados da pesquisa:</h2>
            <div id="Resultado"></div>
            <hr>
        </div>
    </body>
</html>
ajax.js

 function CriaRequest() {
     try{
         request = new XMLHttpRequest();        
     }catch (IEAtual){
         try{
             request = new ActiveXObject("Msxml2.XMLHTTP");       
         }catch(IEAntigo){
             try{
                 request = new ActiveXObject("Microsoft.XMLHTTP");          
             }catch(falha){
                 request = false;
}
}
}
 
     if (!request) 
         alert("Seu Navegador não suporta Ajax!");
else
         return request;
 
}
 
 function getDados() {
     var nome   = document.getElementById("txtnome").value;
     var result = document.getElementById("Resultado");
     var xmlreq = CriaRequest();
 
     result.innerHTML = '<img src="Progresso1.gif"/>';
 
 
      xmlreq.open("GET", "http://192.168.173.59/Contato.php?txtnome=" + nome, true);
     xmlreq.onreadystatechange = function(){
 
 
         if (xmlreq.readyState == 4) {
 
 
              if (xmlreq.status == 200) {
                 result.innerHTML = xmlreq.responseText;
             }else{
                 result.innerHTML = "Erro: " + xmlreq.statusText;
 
}
}
};
     xmlreq.send(null);
 
 }
 

 

 

contato.php

<?php
if (isset($_GET["txtnome"])) {
    $nome = $_GET["txtnome"];
    $server = "localhost";
    $user = "root";
    $senha = "123";
    $base = "agenda";
$conexao = mysql_connect($server, $user, $senha) or die("Erro na conexão!"); 
 
    mysql_select_db($base);
 
   if (empty($nome)) {
        $sql = "SELECT * FROM contato";
    } else {
        $nome .= "%";
$sql = "SELECT * FROM contato WHERE nome like '$nome'"; 
 
}
    sleep(1);
 
   $result = mysql_query($sql);
    $cont = mysql_affected_rows($conexao);
 
   if ($cont > 0) {
        $tabela = "<table border='1'>
                    <thead>
                        <tr>
                            <th>NOME</th>
                            <th>TELEFONE</th>
                            <th>CELULAR</th>
                            <th>EMAIL</th>
                        </tr>
                    </thead>
                    <tbody>
                    <tr>";
        $return = "$tabela";
        while ($linha = mysql_fetch_array($result)) {
            $return.= "<td>" . utf8_encode($linha["NOME"]) . "</td>";
            $return.= "<td>" . utf8_encode($linha["FONE"]) . "</td>";
            $return.= "<td>" . utf8_encode($linha["CELULAR"]) . "</td>";
            $return.= "<td>" . utf8_encode($linha["EMAIL"]) . "</td>";
            $return.= "</tr>";
       echo $return.="</tbody></table>"; 
}
} 
}
?>

Alguém tem uma sugestão, ou isso não é possível?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Exato, o html deve estar dentro do servidor.

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.