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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.