I have an HTML web page on a linux machine. In one JavaScriptfunction I need to run a script (bash/perl/python) on the linux machine, in the same directory the web page is.
The script should get two parameters from JavaScript. It doesn't need to return anything, just to be run.
I tried the following, no luck:
$.ajax({
type: "POST",
url: "script.py"
});
$.post("script.py");
For testing purposes, I used the following python script: import sys
file = open("C:\\file.txt", 'w')
file.close
The script works fine when run manually. Using the AJAX above, I'm getting (on the Developer Tools) this:
syntax error script.py:1:1
syntax error index.html:1:1
The url is fine, as it opens the python script when I click it on the Developer Tools.
Looking at the jQuery docs ( http://api.jquery.com/jQuery.post/ ) you'll find
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
In the data: data change to data : {postName1:myValue1, postName2: myValue2 }
In your scripts you will pick up these name/value pairs via the POST method.
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.