I have an html form, with a jquery script to make it dynamic.
I use Apache2 under debian wheezy for the server,
MongoDB for database,
Pymongo as driver,
At the end, when the form is completed, all the fields are stored in a variable in my .js file, with a json format as follow :
var payload = {"field1":"Richard","field2":"Berroy"} When you click on the submit button, I use an ajax post function :
$("#submitbtn").click( function() { var payload = {"field1":"Richard","field2":"Berroy"} $.post('python/mongo_brief_write.py', {bn: payload}); The goal of mongo_brief_write.py is to insert the content of the payload var into a collection of my MongoDB database, using pymongo driver.
here is my code for this python script :
import pymongo import json import requests from pymongo import Connection //test = {"field1":"Richard","field2":"Berroy"} chain = request.POST[bn] con = Connection("mongodb://192.xxx.xx.xxx/") db = con.central collection = db.brief post_id = collection.insert(chain) If I choose my test var it works fine, but I always have an issue if I comment test and use that request line, I don't now how to get that json object from my jquery form, to store it in the database ?
Thank you
#to comment python code.POST http://192.168.15.200/central/python/mongo_brief_write.py 500 (Internal Server Error) jquery-1.8.3.js:8434 send jquery-1.8.3.js:8434 jQuery.extend.ajax jquery-1.8.3.js:7986 (anonymous function) central.js:910 jQuery.event.dispatch jquery-1.8.3.js:3058 elemData.handle.eventHandle