How to call ajax action from java script function?

supleioss

New Member
I am integrating geolocation API to our application. I have a jsp which contains the java script function for getting the geolocation. I need to pass the address of the client from the this jsp to my form so that i can save it in database. In our application all the ajax functions are defined in ajax-script.js file. when i try to call a method of ajax-script it says \[code\]ajax action variable undefined\[/code\]. My code:ClientLocation.jsp\[code\]<!DOCTYPE html> <%@ include file="/_includes/taglibraries.jsp" %><form autocomplete="off" id="searchNewsForm" action="<%= request.getContextPath() %>/dashboard/news.do" method="POST"><input type="hidden" id="clientLocation"/><html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script><!--<script type="text/javascript" src="http://maps.googleapis.com/maps/api/geocode/json?sensor=true"></script> --> <script type="text/javascript"> var geocoder = new google.maps.Geocoder(); if (navigator.geolocation !== null) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } //Get the latitude and the longitude; function successFunction(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; findCityState(latitude, longitude) } function errorFunction(){ alert("Geocoder failed"); } function findCityState(latitude, longitude) { var formatted_addr = ""; var latlng = new google.maps.LatLng(latitude, longitude); geocoder.geocode({'latLng': latlng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { //formatted address formatted_addr = results[0].formatted_address; } } document.getElementById("clientLocation").value=http://stackoverflow.com/questions/15757423/formatted_addr; submitForm(formatted_addr) alert(formatted_addr); return true; }); } function submitForm(formatted_addr) { var path ="/dashboard/news.do"+"?clientLocation="+formatted_addr; var divName = "clientDIV"; alert(path); submitAjaxAction(path, divName); return true; }</script> </head> <body><div id = "clientDIV" /></body></html> </form>\[/code\]Here i am trying to call submitAjaxAction method of ajax-script.js, so that this action path will lead me to save the property clientLocation in my database.Any help is appreciatedThanks
 
Back
Top