I have a JS script in HTML file which collects input provided by a user. Using the inputed values I form a string and send it to backend Python script via an AJAX call:
$.ajax({
type: "POST",
url: "/cgi-bin/backend.py",
}); data: { 'form_data' : datastring}
The datastring has a value like:
age=9&country=US&buyer=Sample
I see in FireBug the same getting POSTed as:
form_data=age%3D9%26country%3DUS%26....
In my Python backend code I have a check to validate and get the CGI ‘form_data’ variable value:
if self.cgi.has_key ("form_data"):
But surprisingly the code does not enters this ‘if’ code? Also how does the values in the datastring gets changed to ‘age%3D9%26’? If I split the CGI variable by ‘&’ and the parse the splited values by ‘=’ will I be able to get the CGI name value pairs?
First of all the data your sending is getting urlencoded and that is why it looks that way.
You will also need to post your python code if you need any more help with this question. That aside I would advice you to use a python web framework such as Flask or bottle instead of using cgi.