hey everyone,
well i'm creating my own website about geography and i come to a point where i have to use ajax i am quite confident programmer in javascript and php but i have never worked with ajax.
well what im trying to do is have a field where i could enter countries name and at the same time it would retrieve me a population of the country and its capital. the info about population and capital would be stored on the same file(i guess).
is there anybody that could help me work this out or show me a similar example please.
thanks a lot in advance

7 Years
Discussion Span
Last Post by gedas

Why not pre-load some data instead of using AJAX. It makes much more sense to me, but if you insist, have you checked out W3SChools AJAX tutorial?

Here's a little demo of what you're looking for:

function getPopulation(country)
  ajax = getAjax();
    ajax.onreadystatechange = function() { alert(country."'s population is ".ajax.responseText); }
    ajax.open("GET", "population.php?country=".country, true);
    return true;
  return false; //Browser doesn't support AJAX..possibly fall back to hard-coded numbers

function getAJAX()
  if (window.XMLHttpRequest) return new XMLHttpRequest();
  else if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  else return false;

Edited by FlashCreations: n/a


thanks a lot guys it is a good idea for me to read up on ajax a bit more
thanks for your replays and the code

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.