jquery ajax printa index on screen

Asked

Viewed 73 times

0

I’m having problems with jquery because it rather print on the screen only echo of my php it is printing all index on the screen how to solve this ?

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

          setTimeout(

            function(){
              $.ajax({
                url: 'index.php',
                type: 'POST',
                dataType: 'html',
                data: "bin=" + value,
                success: function(resultado){
                  document.write(resultado + "<br>");
              }
            })

          }, 10 * index);

        index = index + 3;

        })
      }
  </script>



<?php





error_reporting(0);

 if ($_POST['ip']) {
$bin = substr($_POST['ip'], 0, 90);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "fonte dps testes");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt( $ch, CURLOPT_POSTFIELDS, "fonte dos testes" );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        $s = curl_exec($ch);
        $pop = preg_match( '/<p>(.*)<\/p>/si' , $s , $match);


$vdd = ' ';

if($pop >= "1") 

{ $vdd = "<b><font color='red'>#DIE_IPS </font></b>"; } 

else { $vdd = "<b><font color='green'>#LIVE_IPS </font></b>"; }


 $tudo = " [".$ip." ".$vdd."] ";


 echo "<br><br><center>".$vdd." ".$ip."</center>";
   }else{}
?>

  • You can show how your PHP code is ?

  • Please also show your PHP,

  • I edited the question there is php

  • @Brunolazarine PHP is bundled with HTML? or in the file, it only has this PHP code?

  • This together and I want to print only the result of php

  • To print only PHP echo, it must be in a file without the presence of HTML

  • More I wish it to be printin the index at the bottom of textarea without redirection as I do ?

  • Use Jquery with a selector. For example if below the textarea you have a div whose id is Response, do : $("#Response"). html(result); This code goes inside the Success in the $.ajax call

  • Thank you for giving me a light, but how I would inplementaria this change in my code ?

Show 4 more comments

1 answer

1


Separate the files, create a PHP-only file. Ex:

IP.php

<?php

$bin = substr($_POST['ip'], 0, 90);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "fonte dps testes");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt( $ch, CURLOPT_POSTFIELDS, "era um garoto=que como eu" );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        $s = curl_exec($ch);
        $pop = preg_match( '/<p>(.*)<\/p>/si' , $s , $match);


$vdd = ' ';

if($pop >= "1") 

{ $vdd = "<b><font color='red'>#DIE_IPS </font></b>"; } 

else { $vdd = "<b><font color='green'>#LIVE_IPS </font></b>"; }


 $tudo = " [".$ip." ".$vdd."] ";


 echo "<br><br><center>".$vdd." ".$ip."</center>";
   }else{}
?>

Otherworldly.html

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

        setTimeout(
            function(){
                $.ajax({
                url: 'IP.php',
                type: 'POST',
                dataType: 'html',
                data: "bin=" + value,
                success: function(resultado){
                    document.write(resultado + "<br>");
                }
            })

      }, 10 * index);

    index = index + 3;

    })
  }
  • Thanks for the more help as I would to print directly on index without any kind of redirect ?

  • @Brunolazarine As I said, it does not update the page, the intention is to return on the same page, so we use Ajax

Browser other questions tagged

You are not signed in. Login or sign up in order to post.