Ajax using Google Maps API call returning -1
-
I’m struggling with using ajax calls in wordpress. I know my ajax calls were working prior to migrating the code into WordPress so it’s really only the wp ajax that is in question. If I enter
https://localhost/wp-admin/admin-ajax.php?wwta_site_fill
into my browser address bar I’m getting back -1. I don’t understand why my function isn’t being found/called.below is the php code from my main plugin file which is setting up the ajax stuff (I’ve tried to trim my code down as much as I could leaving only what’s relevant):
add_action('wp_ajax_ta_site_fill', 'ta_ajax_site_fill'); add_action('wp_ajax_nopriv_ta_site_fill', 'ta_ajax_site_fill'); function ta_ajax_site_fill(){ // qurey DB and build xml data ...snip... // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom->createElement("marker"); $parnode = $dom->appendChild($node); ...snip... echo $dom->saveXML(); die(); } function ta_map_load_scripts(){ $ta_options = get_option('ta_map_options'); wp_register_script('ta_gmap_ref', 'https://maps.googleapis.com/maps/api/js?key=' . $ta_options["api_key"] . '&sensor=false',array(),NULL); wp_register_script('ta_gmap_local_js',WP_PLUGIN_URL.'ta_site_map.js',array(jquery),NULL); wp_enqueue_script('ta_gmap_ref',array(),NULL); wp_enqueue_script('ta_gmap_local_js',plugins_url('ta_site_map.js',__FILE__),array(),NULL); wp_localize_script('ta_gmap_local_js','wp_ta_map_vars',array( 'local_path'=>plugins_url(__file__), 'ajaxurl'=> admin_url('admin-ajax.php') )); } add_action('wp_enqueue_scripts','ta_map_load_scripts');
Here’s my js I’m using google maps javascript api.
//<![CDATA[ function gmap_load() { var map = new google.maps.Map(document.getElementById("map"), { center: --snip-- }); var infoWindow = new google.maps.InfoWindow; downloadUrl( wp_ta_map_vars.ajaxurl + "?ta_site_fill", function(data) { var xml = data.responseXML; var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < element1.length; i++) { var ---snip---; var baloonhtml = "<b> <a target=\"_blank\" href="+wp_wwta_map_vars.local_path+"/site_detail_template.php?siteID=" + siteID + ">" + name + "</a> </b> <br/>" + steloc; var marker = new google.maps.Marker({ map: map, position: point, title: name }); bindInfoWindow(marker, map, infoWindow, baloonhtml); } }); } function bindInfoWindow(marker, map, infoWindow, html) { google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(map, marker); }); } function downloadUrl(url, callback) { var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest; request.onreadystatechange = function() { if (request.readyState == 4) { request.onreadystatechange = doNothing; callback(request, request.status); } }; request.open('GET', url, true); request.send(null); } function doNothing() {} //]]>
Thank you taking the time to look at my issue,
Jason
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Ajax using Google Maps API call returning -1’ is closed to new replies.