1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ajax is ending data premeturly

Discussion in 'JavaScript' started by carlosx2, Feb 24, 2015.

  1. #1
    I have written a piece of code that will install a software on the server. It all works perfectly but for one part of the code.

    When i start using read() and write() it does what it should. I tell it to yum install several softs and then start screen so when the page would fail the install of the software would still continue. So that is all going well. Then i start with installing vestacp for example.

    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("yum install screen wget -y\n");
    $ssh->setTimeout(10);
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("screen\n");
    $ssh->setTimeout(10);
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("curl -O http://vestacp.com/pub/vst-install.sh\n");
    $ssh->setTimeout(10);
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("bash vst-install.sh\n");
    $ssh->setTimeout(10);
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("y\n");
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("\n");
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->write("vps.yourdomain.com\n");
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
    $output = $ssh->read('/.*@.*[$|#]|.*[P|p]assword.*/', NET_SSH2_READ_REGEX);

    So it start the installation process. This is all activated from a ajax function and the data stored in output is being showed by jquery in a div.

    But, and here is the problem. After about a minute ajax is getting the success data back and outputs the $output in a div. When i open the command line and reattach screen -r i see the install is still running. This is also the reason i use screen so i am certain that the process continues even when things go wrong in the browser.

    So now i am looking for a solution to make sure that i do not see the output too soon. What if i would install something that is taking two hours. I want it to show my loading animation for like 2 hours. This is very important or it would like the software installed much faster then it really did.

    Who can help me here.

    thanks.
     
    carlosx2, Feb 24, 2015 IP
  2. carlosx2

    carlosx2 Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    this is how my java script looks like

    $(document).ready(function() {
    $('#eml').focus();

    $('#instbtn').click(function() {
    var a = $('#eml').val();
    var b = $('#pw').val();
    $('.blinstbtn').fadeToggle(300);
    $('.insttext').fadeToggle(300);
    $('#loadingimage').show();
    $.ajax({
    type:"POST",
    url: "functions.php",
    data: {soft : soft, username: username , del : del, a : a, bl_productid: bl_productid, bl_userid: bl_userid, paths : paths, version : version, uniid : uniid},
    success: function(data) {
    $('#loadingimage').hide();
    $('#compinfo').html('<div class="">You have successfully installed <?php echo $softname ?>.<br><br>');
    $('#sshcall').html( data );
    }
    });
    });
    });
     
    carlosx2, Feb 24, 2015 IP
  3. carlosx2

    carlosx2 Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    The solution to my problem was really simple, the timeout was the problem as it was set to 10. This means that it outputs when the server is waiting for connection or to execute a process. Increasing it solved the problem.
     
    carlosx2, Feb 24, 2015 IP