Ok, so first of all, I realize that executing a local file through JavaScript is not possible. Second, I realize that the ability to execute a local file from a webpage is extremely dangerous, and that this question probably looks sketchy. However, my research has shown that it is indeed possible to execute files in the local system without the user realizing using JS by calling the PHP function exec() through AJAX.
Now before I go on, let me just say that I have no intention of using this in a dangerous way. I actually need this for my senior neuroscience/computer science thesis in which I'm:
Working with a wireless brainwave monitoring headset .
I need to sync clicks on webpages to event markers on another computer that's monitoring the brainwaves.
I need to do this without it bothering the user or asking for permission over and over, in the background so as not to interrupt the experiment.
I am currently planning on doing this by writing a Chrome extension which injects a script onto selected pages, selects the element I want, then runs the function on 开发者_运维知识库click from there using AJAX.
So here are my questions:
I'm not super familiar with AJAX and PHP. What is the most straightforward way to set it up so that Javascript calls a PHP file on a click event?
Does anyone know of a web hosting company that does not have the exec() function disabled? I know this sounds sketchy, but I really need this to complete my thesis.
Thanks so much!
$.get or $ajax would be likely functions. ex. $.get(URL, DATA, CALLBACK) data and callback are optional, you can skip if youve got nothing to send and nothing to do on response (which sounds like it might be your case)
http://api.jquery.com/jQuery.get/
http://api.jquery.com/category/ajax/Shouldn't your university be able to help you here?
The computer keeping track of the webpage clicks should store or append the information to a file locally, and the file should be available online. E.g. store your markers to a file locally and install a webserver on the machine so the file can be found online.
Now the machine monitoring the brainwaves can grab the data by using a simple PHP script.
<?php
header('Content-type: application/xml');
$markers = 'ip.address.of.machine/markers.xml';
$handle = fopen($markers, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>
And if you need to incorporate this into a webpage, use Jquery's .load() function to call the script.
$("#markers").load("path/to/file/above.php", function(){
//do your thing
});
精彩评论