[development] AJAX return values

Dan Robinson dan at civicactions.com
Mon May 1 08:44:16 UTC 2006


I am trying to get some AJAX stuff to work -

javascript function -

function setMapContacts(uri, groupname) {
     HTTPGet(uri+"/"+groupname, addContactsToMap, "") ;
}

this is the PHP function that gets called as a result of the above HTTPGet -

function getContacts($GroupName) {
  $contacts = getContactsInGroup($GroupName);
  print drupal_to_js($contacts);
  exit();
}


Here is the callback .js function  I don't think I understand the
correct way to format the callback - "contacts" has no value -

function addContactsToMap(httpresponse, xmlhttp, contacts) {
  if (xmlhttp.status != 200) {
    return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+
httpresponse.uri);   
  }  ;
    map.clearOverlays();
    alert(httpresponse);
}

and I get a dump in httpresponse - the dump has the data i want in it -
but I would much rather be dealing with a javascript array :).  How do I
get a javascript array?  Is there a cast I have to do? 

Thanks,

Dan


More information about the development mailing list