I'm working on a store locator type add-on product for Plone 4.0.2 on Mac OS
X SL, and Mikko Ohtamaa responded to an early post of my detailing a lot of
what i needed to do, but I'm still having some issues and my research isn't
yielding much.
I have a function within my BrowserView class that should use information
POSTed from my javascript file that carries out all of the mapping and
geolocating. I'm new to javascript and ajax so I would assume i have this
wrong but here's my test ajax function and the python function that I want
to POST to.
function createMarkers(center) {
jQuery.ajax( {
type: "POST",
url: "/locatorview.py",
data: { l1: center.geometry.location.lat(), l2:
center.geometry.location.lng(), r: document.getElementById('radius').value},
success: function (data) {alert("Data loaded: " + data);},
dataType: "xml"
});
}
----------------------------------------------------------------
def searchDealers(l1, l2, r):
l1 = str(l1)
l2 = str(l2)
r = str(r)
settings = getUtility(IDatabaseSettings)
mydb = mysql.connect(host=settings.hostname,
user=settings.username,
passwd=settings.password,
db=settings.database)
cur = mydb.cursor()
cur.execute('SELECT name, address, lat, lng, ( 3959 * acos( cos(
radians('+l1+') ) * cos( radians( lat ) ) * cos( radians( lng ) -
radians('+l2+') ) + sin( radians('+l1+') ) * sin( radians( lat ) ) ) ) AS
distance FROM dealers HAVING distance < '+r+' ORDER BY distance LIMIT 0 ,
25')
results = cur.fetchall()
doc = Document()
markers = doc.createElement("markers")
doc.appendChild(markers)
for row in results:
marker = doc.createElement("marker")
marker.setAttribute("name", row[0])
marker.setAttribute("address", row[1])
marker.setAttribute("lat", str(row[2]))
marker.setAttribute("lng", str(row[3]))
marker.setAttribute("distance", str(row[4]))
markers.appendChild(marker)
mydb.close()
return doc.toprettyxml()
I'm guessing that my problem is with the URL. I'm not really sure how to get
to that python script within Plone, let alone access a specific function. My
code needs to be refined quite a bit before i finish this project, but until
i get the dialogue going between my python and javascript I'm pretty much
stuck where I'm at. (I'm an intern working at a company new to plone
development, and have very little in house assistance)
Incase it's import my .js file is located
@portal_skins/locator_js/locator.js
Any guidance would be greatly appreciated.
--
View this message in context:
http://plone.293351.n2.nabble.com/AJAX-POST-to-specific-function-in-product-BrowserView-Class-tp5838117p5838117.html
Sent from the Product Developers mailing list archive at Nabble.com.
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers