Graham Dumpleton
graham.dumpleton at gmail.com
Mon Dec 8 22:25:24 EST 2008
2008/12/9 wayne collier <Wayne.Collier at noaa.gov>: > I am trying perform AJAX function call on my website using Spry framework. I > am a little lost on how to send data to my python function. I was able to > get the following code to work using urlparse commandas in server code. > However, can get this going using the standard mod_python/vampire construct > (e.g. ss=req.form['data1_value'] ). I can't seem to grab the postdata I am > placing in the > Spry.Utils.loadURL command. Can someone help me with this? > > Wayne > > JAVASCRIPT: > > <script> > function ajax_request(){ > var data1_value = document.sample.first.value; > var data2_value = document.sample.last.value; > var formData = 'first='+data1_value+'&last='+data2_value; > //The next line is to encode the variables values e.g. weird characters > to make it safe for transfer > formData = encodeURI(formData); > var > url="http://mingus.ncd-tcn.noaa.gov/dev/python/jsonExample.py/breakthru?"+formData; > formData = encodeURI(formData); > var req=Spry.Utils.loadURL('POST', url, true, > ReturnTask,{postdata:formData, headers:{"Content-Type": > "application/x-www-form-urlencoded; charset=UTF-8"}}); > > //-------------------------------------------------------------------------------- > function ReturnTask(req){ > //We use xhRequest to received notification from server side, usually the > process file will return with an echo/write. > var result = req.xhRequest.responseText; > document.getElementById("notice").innerHTML =result; > } > > } > </script> > > > SERVER CODE: > > def breakthru(req): > # req.content_type='text/html' > from cgi import escape > from urllib import unquote > import vampire > import mod_python > from mod_python import util > from urlparse import urlparse > > d={"first":"Stevenrr","last":"Spielberg","address":"1234 Unlisted > Drive"} > > for attrib in dir(req): > attribs += '<tr><td>%s</td><td>%s</td></tr>' > attribs %= (attrib, > escape(unquote(str(req.__getattribute__(attrib))))) > > test=util.parse_qs(str(req.__getattribute__('args'))) > > first=test['first'][0] > last=test['last'][0] > > req.write(str(test)+ '<br>') > return "<br> name:" +first What is the Apache configuration related to mod_python that you are using so can see exactly what parts of mod_python/Vampire you are trying to use. If you are trying to use req.form, why isn't it mentioned in your server code? Graham
|