I have one test.html:
<form action="/cgi-bin/test.py" method="GET">
<input type="text" name="search">
<input type="submit" value="Submit">
</form>
<div id="res"></res>
And one python script test.py:
#....
print Result
#....
I want instead of printing result on the test.py, return it to the test.html and write it in the div with id res... How I can do that?
-
you are probably looking for json ...Joran Beasley– Joran Beasley2012年10月31日 23:26:49 +00:00Commented Oct 31, 2012 at 23:26
-
@Joran Beasley What you mean? Can show example?a1204773– a12047732012年10月31日 23:29:47 +00:00Commented Oct 31, 2012 at 23:29
-
@JoranBeasley I think he needs a python template engine and not json.rantanplan– rantanplan2012年10月31日 23:29:50 +00:00Commented Oct 31, 2012 at 23:29
-
Actually I have no clue to what you're asking. Could you give us more details on what is your intent exactly?rantanplan– rantanplan2012年10月31日 23:36:05 +00:00Commented Oct 31, 2012 at 23:36
-
I made a script that its result give an embed player <embed ....></embed> and instead of printing it there I want to print in the html that called the script and show that embed player inside div with id resa1204773– a12047732012年10月31日 23:38:30 +00:00Commented Oct 31, 2012 at 23:38
3 Answers 3
<form id="myform">
<input id="my_text">
<button id="submit_btn">
</form>
<div id="result">
</div>
<script>
//you need to use jquery for this part
$("#submit_btn").click( function() {
$("#result").load("/path/to/cgi?my_text="+$("#my_text").val())
})
</script>
something like that... (this is real hacky 1 minute post that is untested so it may need some work ...
your question really has nothing to do with python ... it is just web technology question ... it would be the same if it was a php or C# or whatever processing the form data
it has nothing to do with python because it doesnt matter how you are processing the form data ... this is just web technology it would work exactly the same with a perl script instead of a python script or with a C# instead of python or whatever ... you want to return some data back to a web page ... how you got the data is really not relevant
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<form action="someother.html" method="get">
<input id="my_text">
<input type="button" id="my_button" value="click me">
</form>
<div id="result">
</div>
<script>
$("#my_button").click(function(){
$("#result").load("");
})
</script>
</body>
</html>
here is an example ... just paste it into a file.html and go to it and click the button ...
its just loading its self load("") so it should duplicate the data thats on the page when you click it ...
6 Comments
Well I understood your question in this way, maybe you are looking for other thing but i know a way that do exactly what are you looking for: Ajax.
Just make an ajax request to the cgi python and put the response into a div. Luckily, this is very easy nowadays.
If you know something about jQuery (a javascript framework) you should visit this link to getting started: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax
byeeee
6 Comments
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Hello - Second CGI Program</title>"
print "</head>"
print "<body>"
print "<h2>Hello World</h2>"
print "<p>Executing HTML code from python script</p>"
print "</body>"
print "</html>"