简体   繁体   中英

How to run php script from jQuery - on button click

I have a simple PHP script that sits in the home directory of my webserver. I also have a button called "campausebtn". I want to simply click the button and then call the php file using jquery. I've read many posts on SO and it seems simple, but I can't get it to work.

I've tried the following script:

<script>
jQuery(document).ready(function(){

    jQuery("#campausebtn").click(function(){

        alert("Paused Clicked!");

        $.ajax({
            url: 'camera_pause.php',
            success: function() {
                alert("Paused!");

            }
        });

    });

});
</script>

The "Paused Click" alert is working fine, so I know the jQuery and button are working. It just wond't run the script.

Please can someone help?

Thanks Chris

Try it like this...

$.ajax({
  method: "POST",
  url: "camera_pause.php",
})
  .done(function( msg ) {
    console.log( msg );
  });

otherwise read the documentation on it: https://api.jquery.com/jquery.ajax/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM