Printing php results in divs

0

<html>

<head>
  <title> chk </title>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script>functionenviar(){varlista=$("#lista_id").val();
      var linhaenviar = lista.split("\n");
      var index = 0;
      linhaenviar.forEach(function(value) {

        setTimeout(

          function() {
            $.ajax({
              url: 'config.php',
              type: 'POST',
              async: false,
              dataType: 'html',
              data: "lista=" + value,
              success: function(resultado) {
                $('#oi').html($('#oi').html() + resultado + "<br>");
              }
            })

          }, 10 * index);

        index = index + 1;

      })
    }
  </script>

</head>

<body>
  <center>
    <textarea name="lista" id="lista_id" rows="10" cols="40">
</textarea>
    <br>
    <input type="button" value="testar" onclick="enviar();"></input>
    <br>
    <div id="live" name="live">
      <p></p>
    </div>
    <div id="Die" name="Die">
      <p></p>
    </div>
  </center>
</body>

</html>

//PHP SEPARADO NO CONFIG.PHP

<?php

$checker = $_POST["lista"];

$ip = explode("|", $lista)[0];
$porta = explode("|", $lista)[1];

function GetStr($string, $start, $end){

$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}

$login = ''.$ip.' | '.$porta.'';

$ch = curl_init();
$url = "local da requisição";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "_proxy=$ip&_port=$porta");
$resultado = curl_exec($ch);
curl_close($ch);

$name = $resultado;
$valor = GetStr($name, 'Sair',";");

if ( $valor == "Sair" ) {
 echo '<script>$(document).ready(function(){$("#Live").prepend("'.$login.' <br>")});</script>' ;
} else {

    echo '<script>$(document).ready(function(){$("#Die").prepend("'.$login.' <br>")});</script>' ;
}


?>

How do I display the results of my PHP in a div ? Follow my code, I want every result to be displayed on your div .

if ( $valor = "Sair" ) {
 echo '<script>$("#funcionou").prepend("'.$logout.' <br>");</script>' ;
} else {

    echo '<script>$("#naofuncionou").prepend("'.$logout.' <br>");</script>' ;
}


<div id="funcionou" name="Lives">

</div>

<div id="naofuncionou" name="Dies">

</div>
    
asked by anonymous 01.09.2017 / 02:13

1 answer

2

First, the = operator is incorrect on the line:

if ( $valor = "Sair" ) {

The correct one would be to use == ( comparison operators PHP ):

if ( $valor == "Sair" ) {

Updating the answer:

In your code you play the Ajax return inside a div with id="hi", but this div does not exist in your HTML. You need this div so that the script coming from Ajax takes effect.

<script>
function enviar() {
      var lista = $("#lista_id").val();
      var linhaenviar = lista.split("\n");
      var index = 0;
      linhaenviar.forEach(function(value) {

        setTimeout(

          function() {
            $.ajax({
              url: 'conecta.php',
              type: 'POST',
              async: false,
              dataType: 'html',
              data: "lista=" + value,
              success: function(resultado) {
                $('#oi').html($('#oi').html() + resultado + "<br>");
              }
            })

          }, 10 * index);

        index = index + 1;

      })
    }
</script>

Correct code in Ajax (in PHP):

if ( $valor == "Sair" ) {
 echo '<script>$("#funcionou").prepend("'.$logout.' <br>");</script>' ;
} else {

    echo '<script>$("#naofuncionou").prepend("'.$logout.' <br>");</script>' ;
}
    
01.09.2017 / 03:08