hi,
i want to display output line by line using jquery.i tried many times but it not works..pls help me..

Html Code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#sub').click(function(){
$('#msg').html("<center><img src='http://46.16.168.75/saranya/images/9%20(1).gif' alt='LOADING...' width='20' height='20'/>Loading........</center>");

 $.ajax({
               type: "POST",
               url: "ping1.php",

               data: $("#form1").serialize(), 

               success: function(data)  {
               $('#msg').html(data);
                alert(data);

                }
            });

       return false;
    });
 });
</script>
<div id="tag">


<form id="form1" method="" action="">
<input name="ip" type="text"/>
<!--<button id="sub">submit</button>-->
<input type="button" name="submit" id="sub"  value="submit"/>
</form>
</div>
<div id="msg"></div

Php:

<?php




$ip=$_POST["ip"];

header('Content-Encoding: none;');

set_time_limit(0);

$handle = popen("ping -c 4 $ip", "r");

if (ob_get_level() == 0) ob_start();
while(!feof($handle)) {

$buffer = fread($handle,1024);
$buffer = trim(htmlspecialchars($buffer));

echo $buffer . "<br />";
echo str_pad('', 4096); 

ob_flush();
flush();
}

pclose($handle);
ob_end_flush();





?>

if i submit the form using php it will show the output in line by line..but i use jquery to submit the form means it will display the output but not in line by line.

Recommended Answers

All 5 Replies

First thing that comes to mind:

Make the PHP script that does the pinging (ping.php) write its results to, for example, ping_results.txt. Then, make an AJAX call to ping.php and immediatelty after execute a Javascript timeout that executes an AJAX function every 0.5 or 1 seconds, which opens ping_results.txt and outputs the results.

hi,
are you saying,i have to save ping.php results as a text file and then execute the result using ajax .

Yea. Because if you just call the PHP script that is pinging, it will wait untill all pinging is done and return everything at once. If you make each ping write a line to a text file for example, you could then check that text file very 0.5 seconds or so to check if any new lines have been added, and display those.

hi,
i want permutation for all alphabets with word length is 8.but i get only permutation for 4.pls help me to debug this issue

code:

<?PHP



    FUNCTION permutations($letters,$num){ 


$last = STR_REPEAT($letters{0},$num); 
$result = ARRAY(); 
WHILE($last != STR_REPEAT(lastchar($letters),$num)){ 
echo "$last";
$result[] = $last; 
$last = char_add($letters,$last,$num-1); 
} 
$result[] = $last; 
RETURN $result; 
} 
FUNCTION char_add($digits,$string,$char){ 
IF($string{$char} <> lastchar($digits)){ 
$string{$char} = $digits{STRPOS($digits,$string{$char})+1}; 
RETURN $string; 
}ELSE{ 
$string = changeall($string,$digits{0},$char); 
RETURN char_add($digits,$string,$char-1); 
} 
} 
FUNCTION lastchar($string){ 
RETURN $string{STRLEN($string)-1}; 
} 
FUNCTION changeall($string,$char,$start = 0,$end = 0){ 
IF($end == 0) $end = STRLEN($string)-1; 
FOR($i=$start;$i<=$end;$i++){ 
$string{$i} = $char; 
} 
RETURN $string; 
} 
?> 








<?php
for($j=1;$j<9;$j++){
$Array=permutations("ABCDEFGHIJKLMNOPQRSTUVWXYZ",$j); 
FOR($i=0 ; $i < COUNT($Array) ; $i++) { 
ECHO "$i." . $Array[$i] . "<BR>"; 
} 
}
?> 

output:

i want a output like this
a
b
c
d
e
f
.
.
.
.
.
z
aa
ab
ac
ad
.
.
.
.
.
.
az
.
.
.
.
.
.
.
.
.
.
zzzzzzzz

But the above code shown like this
a
b
c
d
.
.
.
.
.
aa
ab
ac
.
.
.
.
az
.
.
.
zzzz
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.