0

Basically I want to have a button on my HTML/PHP page which will once clicked send a call to another php page which will update a value in mysql table.

    <html>
    <head>
    <script>
    src = "https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
    function toggleText(button_id){
            if(document.getElementById(button_id).innerHTML == "Uninstall All"){
                    document.getElementById(button_id).innerHTML = "Cancel Uninstall";
                    //ajax////////////////////
                    xmlhttp = new XMLHttpRequest();
                    xmlhttp.open("GET", "valueChange.php?uninstalled=1&type=all", true);
                    xmlhttp.send();
                    ////////////////////////
            }
 }
    </script>
    </head>

I'm curious why this isn't working.

I had tested my toggleText function without the ajax and it changed the HTML properly.

But once I add in the ajax to visit this valueChange.php page and update an sql value it doesn't work.

I've tested the php page by itself and it properly updated the value in sql.

I've never used ajax so I'm curious if I'm doing it wrong? I thought my src = "google/ajax/jquery" was the way to install it. Or is there a library I need to install on the VPS hosting my site?

2
  • Whats the ajax code. Commented Nov 27, 2016 at 1:37
  • I thought the xmlhttp object was ajax? Took it straight off W3 schools. Commented Nov 27, 2016 at 2:03

1 Answer 1

2

The only mistake I see in above code is just a typo. See line 3 you closed the script tag before the second attribute it should have been <script src="*link to jQuery*" ></script>

And another thing you don't need to use the jQuery library to use XMLHttpRequest() method.

The modified code:

<html>
<head>    
<script>
 function toggleText(button_id)
{
        if(document.getElementById(button_id).innerHTML == "Uninstall All")
            {
                document.getElementById(button_id).innerHTML = "Cancel Uninstall";
                //ajax////////////////////
               var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", "valueChange.php?uninstalled=1&type=all", true);
                xmlhttp.send();
                ////////////////////////
        }
}
</script>
</head>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.