Jump to content

Retrieve Database Data (Ajax)


Dysan

Recommended Posts

  • 2 months later...
  • 2 weeks later...

I use frameworks only these days for my ajax funtionality prototype and and mootools do a great job with this. It makes you able to write a few simple lines instead of using the usually long script.

 

for example instead of using this which is a pain to modify for starters and i know i have been there

var xmlHttp

function showCustomer(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getcustomer.asp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

 

you can use this

//when the button start is clicked the ajax function will start
$('start').addEvent('click', function(e) {
e = new Event(e).stop();
       //the external page that will be loaded
var url = "http://demos.mootools.net/demos/Ajax/lipsum.html";

/**
 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
 * to do add your own Ajax depended code.
 */
new Ajax(url, {
	method: 'get',
	update: $('log')//the element log that will be updated <div id="log"></div>
}).request();
});

 

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.