Disable a button in a set of buttons (PHP Jquery)

Asked

Viewed 77 times

0

I did a script on Jquery for the installation of software by that of a script PHP.

The Jquery takes the installation request via a button created in a script HTML and calls the PHP that makes the installation by shell_exec.

This part works perfectly, now I needed to make a check if the software is already installed on the machine and disable only the button referring to the installed software.

What I had thought was to check through a script PHP and send by means of a JSON for a script Jquery the software installed so that this script disables the button referring to them, but I’m not sure how to do it, if anyone can help thank you.

Follow the codes of Jquery and of PHP who do the installation.

//Jquery

function instalaSoftware(software){
    console.log(software.data.software)  
    $.get("instalaSoftware.php?software="+software.data.software)
}

$(document).ready(function(){
    $("#soft1").click({software:'soft-1'},instalaSoftware)
    $("#soft2").click({software:'soft-2'},instalaSoftware)
    $("#soft3").click({software:'soft-3'},instalaSoftware)
    $("#soft4").click({software:'soft-4'},instalaSoftware)
    $("#soft5").click({software:'soft-5'},instalaSoftware)
}

//PHP script (instalaSoftware)

<?php
$softwareId = $_GET ["software"];

if($softwareId != ""){
    $up = shell_exec("sudo apt-get update");
    $softwareInstall = shell_exec("sudo apt-get -y --force-yes install $softwareId");
    echo $softwareInstall;
}
?> 
  • I temporarily removed the reply. Your last comment was like this: "That way it didn’t work out for the way I need it. I wanted in a new PHP script to be able to check if the software is installed in the folder with a type command:"... was incomplete at the end.

  • I sent it without finishing. Sorry. So, the solution you sent me is disabling all the buttons. He is unable to read what JSON looks like, but I also don’t know if my PHP code he produces is right, he is as follows: $softName = $_GET["software"]; for ($softName = 0; $softName < 4; $softName+) { $softFind = shell_exec("cd/var/www"). shell_exec("ls | grep $softName"); Return $softFind; }; header('Content-Type: application/json'); echo json_encode($softFind);

  • Right. The solution I put should disable only the button with the id passed in the function after the return of Ajax $.get. In this case, if you refresh the page, the button will return to normal.

  • Could you explain to me how it works to . repleace()? I didn’t really understand her function, I’m still new to script.

  • The value of software.data.software is soft-1... the id of the button is soft1, soon would have to eliminate this hyphen - to match the id of the button. replace this, replace the hyphen with empty: string.replace('-', '');...

  • It seems to me that the problem is that it cannot read the installed software that is contained in the JSON file to disable only the buttons referring to the already installed software. I don’t know how to make him read the JSON and compare the button ids with the ids that are in the file, then check if they are the same and disable the referring buttons. This considering that my PHP script is right...

  • But is JSON coming right? Where is it coming from?

  • Yes, it is. It comes from a PHP script that I call the ajax url.

  • So it’s another case. In the question of the click was what I really put. Do you want to disable the buttons when loading the page using this JSON that you refer to? What is the Ajax that receives this JSON?

  • That. When loading the page it checks which software is installed and disables the buttons related to them to prevent the user from trying to install the same software twice. I made a separate JS script to do the JSON reception and button disablement process. $.ajax({ type: "GET", dataType: "JSON", url: "verificaSoftware.php", Success: Function verificaSoftware(software){ //Cod of JSON comparison with the id of the buttons } });

Show 5 more comments
No answers

Browser other questions tagged

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