What's the very simplest way to run some Python from a button on a web page?

T

tinnews

I want to run a server side python script when a button on a web page
is clicked. This is on a LAMP server - apache2 on xubuntu 11.10.

I know I *could* run it as a CGI script but I don't want to change the
web page at all when the button is clicked (I'll see the effect
elsewhere on the screen anyway) so normal CGI isn't ideal.

It's easy to show a button:-

<INPUT TYPE=submit NAME="Button" ONCLICK=something>;

Can I get away with something clever for 'something' that will somehow
hook through to a server side script?

Alternatively, seeing as both client and server are on the same
system, this *could* be done on the client side by breaking out of the
browser sandbox - is there any easy way to do this?


I'm just looking for the crudest, simplest possible way of doing this,
it's only for my own convenience to fire up a utility I want to use
when viewing certain of my local HTML pages. These pages aren't
visible from the outside world so security isn't a big issue.
 
C

Chris Angelico

It seems what you're after is AJAX.  If you are using a Javascript
framework like jQuery, it's easy to fire off an asynchronous request back
to your server that leaves the existing page alone.

If you aren't using a framework, look up the XMLHttpRequest object -
that's what does the work. As Tim says, there's no lack of good
material on the subject.

ChrisA
 
T

tinnews

Tim Roberts said:
It seems what you're after is AJAX. If you are using a Javascript
framework like jQuery, it's easy to fire off an asynchronous request back
to your server that leaves the existing page alone. If you aren't, then I
think the easiest method is to use an invisible <iframe>. From Javascript,
you can set the "src" property of the <iframe> to fire off a request while
leaving the rest of the page alone.
OK, thanks, I'd sort of found that the answer seems to be AJAX but now
you have confirmed it I'll start looking harder.

You could spend the rest of your career reading all of the good web
material on AJAX.

:)
 
T

tinnews

Chris Angelico said:
If you aren't using a framework, look up the XMLHttpRequest object -
that's what does the work. As Tim says, there's no lack of good
material on the subject.
OK, thanks both, with those pointers I think I'm on the way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top