Solved

Calling javascript from perl with Ajax

Posted on 2013-10-23
2
351 Views
Last Modified: 2013-10-28
Hi,
I have a web page with a Google Map on it. The google map shows the user their current location (using HTML5).
There is a drop down on the page with some town names.
When a user selects a town name from the drop down, the event fires off a javascript function using AJAX, which then calls a perl script. The perl script queries a database and gets coords for the town the user selected in the drop down.
The next thing I *want* to do is place a marker on the map that shows the person where the town they selected is.
The part that has got me stumped is once I am in the perl script through the Ajax call, how do I pass the coords back to a javascript to put the marker on the map?

The only solution I can think of is to redraw the entire page in the perlscript, passing the coords to a javascript function using something like this
<body onload=placeMarker(lat1,lat2)>
I was hoping there was some other way I could do it that would be more elegant that would allow me to just pass back coords to the javascript without having to redraw the whole page.

Anyone?

Thanks,
Nacht
0
Comment
Question by:nachtmsk
2 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
I believe that all the code you need is on this page: https://developers.google.com/maps/articles/phpsqlsearch_v3  That version returns the info in XML format.   On this page https://developers.google.com/maps/documentation/javascript/basics , they have a link to a lot of code sample for different displays.
0
 

Author Closing Comment

by:nachtmsk
Comment Utility
Just what I needed. Thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now