How to run a python script with arguments via the click of a button in javascript
<p>So I've written a program in JavaScript that outputs a JSON. What I want to do is, with the click of a button, I want to pass in that JSON as an argument to a python script.</p>

<p>I am not entirely sure how to proceed with this:</p>

<pre><code>$.ajax({
url: "/path/to/your/scriptPython",
success: function(response) {
  // here you do whatever you want with the response variable
}
});
</code></pre>

<p>Any feedback or help is appreciated.</p>

<p>This depends on one important consideration: where is your Python code?</p>

<p>If you want the Python to run on the user's machine, that gets complicated due to security measures: websites generally aren't allowed to execute arbitrary code on viewers' machines. (Imagine if that Python code wiped their hard drive, for instance.) In this case it might be best to have users download the JSON as a file, and then open that with your Python program.</p>

<p>If you want the Python to run on your server, you can make a POST request to the script's endpoint, and pass the JSON in the POST data. The details of this will depend on your choice of Python web framework (I'm fond of Flask), but the Javascript would be pretty much the same:</p>

<pre><code>$.ajax({
    type: 'POST',
    data: my_json_variable,
    url: 'http://example.com/python_endpoint',
    success: function(response){ /* deal with the script's output */ }
});
</code></pre>

javascript python ajax