0

I have a python script that take raw_input, stores in a varible and then uploads the input to a database. Iwant to use javascript to create the web front end for this(which I have) but I need toknow how to tie the two together. Any help would be great

2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by bgeisel1
0

Hi lockdon,

You'll have to output it in a format you can suck it in from JavaScript. Depending on the data, you'll probably want to use XML or JSON. Since you're constructing the data format here, you can do it manually if the data is simple enough. With more complex data, you might look at the json module (import json) for Python, or one of the XML libraries. Last I remember minidom was the simplest for most things.

From there, it just depends on whether Python is generating the page, or if you're pulling data asynchronously from the JavaScript. The asynchronous version means your Python just needs to output the XML or JSON directly. If you're using Python to create the page and that's where your data goes, then you'll just need to do something more like:

print "var jsData='%s';" % dataString;

If my Python syntax is off, we can call it pseudo-code, but you get the idea. Then JavaScript can just use the jsData variable, assuming you've output that inside your <script> tags in the HTML.

HTH!
-Brian

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.