I have this php file:
<?
function bb(){
system( 'python my_script.py');
echo "done";
}
bb();
?>
I would like to execute this, using ajax. I do it this way:
<script type = "text/javascript">
function myAjax () {
$.ajax( { type : 'POST',
data : { },
url : 'action.php', // <=== CALL THE PHP FUNCTION HERE.
success: function ( data ) {
alert( data ); // <=== VALUE RETURNED FROM FUNCTION.
},
error: function ( xhr ) {
alert( "error" );
}
});
}
</script>
This is executed when a button is clicked:
<button type="button" class="btn btn-outline-danger" onclick="myAjax()">Primary</button>
The problem is that i get always error case. Even if my php file should execute only echo (i.e. deleting system). How can i solve that?
Using Chrome inspector, under Network tab i get this error:
jquery.js:4 XMLHttpRequest cannot load file:///Users/Antonio/Desktop/script/action.php.Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
but the file is accessible using this path.
file:///Users/Antonio/Desktop/script/action.phpbuthttp://localhost/action.php.