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

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();
  if(ajax)
  {
    ajax.onreadystatechange = function() { alert(country."'s population is ".ajax.responseText); }
    ajax.open("GET", "population.php?country=".country, true);
    ajax.send(null);
    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;
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.