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

 

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.