Support » Fixing WordPress » Basic Ajax help

  • Resolved AJ Mallory


    I’m struggling with using ajax calls in wordpress. I’m pretty sure I’m not fully understanding how it works (I don’t know javascript all that well) and I’m hoping some one can give me a couple of pointers. 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. I’ve tried to trim my code down as much as I could leaving only what’s relevant.

    below is the php code from my main plugin file which is setting up the ajax stuff:

    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
    	// Start XML file, create parent node
    	$dom = new DOMDocument("1.0");
    	$node = $dom->createElement("marker");
    	$parnode = $dom->appendChild($node);
    	echo $dom->saveXML();
    function ta_map_load_scripts(){
    	$ta_options = get_option('ta_map_options');
    	wp_register_script('ta_gmap_ref', '' . $ta_options["api_key"] . '&sensor=false',array(),NULL);
    	if( !is_admin() ){
    			'ajaxurl'=> admin_url('admin-ajax.php')

    Here’s my js I’m using google maps javascript api. And I think this is were I’m having my issue downloadUrl( wp_ta_map_vars.ajaxurl + "&ta_ajax_site_fill", see below for the context if necessary.

        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_ajax_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() {
  , 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);
'GET', url, true);
        function doNothing() {}

    Thank you taking the time to look at my issue,

Viewing 2 replies - 1 through 2 (of 2 total)
  • So I discovered I had a couple of typos in the line referenced above. Here is the corrected version: downloadUrl( wp_ta_map_vars.ajaxurl + "?ta_site_fill",...

    Now if I manually call the ajax from the browser I’m getting back a “-1” so the call is failing. I’m not sure why? Thoughts?


    Noticed this post was created in the wrong sub form. I’ve re-posted to hacks and closing this one.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Basic Ajax help’ is closed to new replies.