I have javascript HTML page which has an action POST to a python file. The python code is supposed to send back a JSON to the HTML. I just do not know how to catch the JSON and parse it. I think I can parse it fine if I catch it, and for the life of me I can't get this to work. Below is the HTML code excerpt as well as the python code excerpt. The JSON is even supposed to be really simple with just one value in it!
HTML CODE EXCERPTS:
<form action="http://www.MYURLHIDDENHERE.com/cgi-bin/new.py" id="form" method="post" enctype="multipart/form-data" target="resIframe">
<div style=" width: 0px; height: 0px; overflow: hidden;" >
<input type="hidden" name="random" id="random" value="">
<iframe src="" name="resIframe" id="resIframe" onload="iframeLoaded();" ></iframe>
</div>
And here's where I try to catch it:
function iframeLoaded() {
var result = $.parseJSON($("#resIframe").contents().find("html").html())
.....
}
I wonder if I am doing something wrong with the "target" stuff above? If I print $("#restIframe") its just an [object Object]. Essentially I am not sure if I am catching the JSON response back in HTML.
And here's the py code excerpt:
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
import cgi, os
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
data = {'score': 50}
print "Content-Type: text/html"
#print "Content-Type: application/json"
print
print json.dumps(data)
I've spent HOURS on this and read numerous examples/blogs so any help would be really appreciated!