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);
    }
  }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.