How do i run a PHP function inside jQuery click event. I have the following which is not correct. when the user clicks on a button, i want a new directly created.
First of all you should understand how php works (no offense but this is essential). Why PHP script is not workig in a web browser? To accomplish what you need you have to use ajax (to request a script on the server using javascript)
PHP File (createdir.php):
<?php
mkdir('/test1/test2', 0777, true);
?>
JavaScript Code:
$('button').click(function() {
$.ajax({
url: 'createdir.php',
success: function(){
alert('dir created');
}
});
return false;
});
I have not validated if the code acually works. If you encounter any problems you should have a look at the jquery documentation (it's awsome :-) ) http://api.jquery.com/jQuery.ajax/
you have to do:
//mkdir.php
<?php mkdir('/test1/test2', 0777, true); ?>
<script>
$('button').click(function(){ $('#hidden').load('mkdir.php'); return false; })
</script>
<div id='hidden' style='display:none;'></div>
Buddy , first of all understand that jquery is a client side programming language which is running on clients browse and Php runs on webserver .Copy the php code in to a php file and create a request to the php file from jquery using
$.ajax();