Jump to content

Kindly tell me how this Ajax code will work


balasund.mca

Recommended Posts

Hi,

 

In the frontend, upon clicking a button I get contact details through the below ajax script. Now I want to know what does the code inside this component do. Does it only read the contact details OR does it also write something in the database.

 

The code is this

 

<a href='javascript:void(0);' onclick="getDetails('MnP-JGckeyE+2222=1','JGckeyE%2222%3D1');"

 


function getDetails(rowId,uname)
{
try
    {
      ajaxRequest = createXmlHttpRequest(showContact,rowId);
    }
    catch(error)
    {
      ajaxRequest = null; return false;
    }
    var params = "?uname=" + encodeURIComponent(uname)+ "&sid="+ sid + "&xhr=1";
    ajaxRequest.open("GET",gbi("getContactNumUrl").value+params,true);
    ajaxRequest.send(null);
    return false;

}
function showContact(rowId)
{
  // when readyState is 4, we are ready to read the server response
  if (ajaxRequest.readyState==4)
  {
    // continue only if HTTP status is "OK"
    if (ajaxRequest.status == 200)
    {
      try
      {
        var html = ajaxRequest.responseText;
        gbi(rowId).innerHTML = html;
      }
      catch(e)
      {
        alert("Error reading the response: " + e.toString());
      }
    }
    else
    {
      alert("There was a problem retrieving the data:\n" +ajaxRequest.statusText);
    }
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.