How to run a Python script upon button click using mod_python without changing browser window

Ashill Chiranjan

I am using mod_python publisher which is set up and working fine. It allows me to run a Python file in my browser and this Python file has HTML embedded in it. I have defined a click-able image by input type = "image" onclick = "some action". When I click the image it takes me to a JavaScript function which then performs window.location = "./move" which then takes me to a Python function. The problem is that the browser window redirects to that function, i. e. localhost/scripts becomes localhost/scripts/move. Is it possible to execute the script without having the browser window change? I can post code if needs be.

Alexandre Mazel

In fact, I've just found using Ajax/XmlHttpRequest is simple and work well for that, even if your server is a python SimpleServer style.

You just link this Javascript code from your button:

// send a request, but don't refresh page
xhttp = new XMLHttpRequest();
xhttp.open("GET", "?like", true);
xhttp.send();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to click A button on the second window of the browser using Selenium with python

Python, selenium - How can I run the script without showing the browser window

How to run a python script in a terminal upon login?

How to run python script on Google Colab without changing directory

How to run a python script with arguments via the click of a button in javascript

How to click a button in Tor Browser with Selenium and python

How to run python script on terminal without using python3?

Python run script upon mail reception

How to run python scripts on button click in React?

I am trying to run a python script from a click of a button in my HTML code using Ajax

How to run a Python program without a window?

Changing contents of a modal upon a button click

how to run python script without typing 'python ...'

Run python script in VB.net on button click

Run Python script as an exe without showing a command window

How to run python script on clicking button?

How to run methods in onCreate() without button click

How to run PowerShell script without terminal window?

Can't run python script in browser using Spyder IDE

How to click on confirmation button using Selenium with Python?

How to click Radio Button using python Selenium

How to click on dynamic button using selenium Python?

How to click the button to crawl the reviews using python

How to click on the Search button using Selenium and Python?

How to click the button using selenium python

How to click this button on this URL using selenium and Python?

How to click on the text button using selenium python

How to click this button using Selenium through Python

How to click iframe button on Python using Selenium?