Categories: javascript, php, jquery

How to run php script from jQuery - on button click

1 answer

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

Received answer to this question:
The best answer according to the author of the question:

Try it like this...

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

otherwise read the documentation on it: