Jump to content

Very simple and basic displaying results from mysql into ajax div


Shaun

Recommended Posts

Hi there, I was just wondering if anyone could help me.

 

I want to convert the code output div on my site http://www.sigchat.com/59 (example)

 

So when someone clicks on the "Want to add this Chat to your Sig, Website or Blog? Click here for the code" link, it will pull the code from the database only when someone clicks the link.. At the moment, it is being pulled from the database on every page load and is just hidden with a div until someone clicks it to expand it.

 

I just want to try and eliminate wasted resources and only load the data from mysql when they actually click on it.

 

im new to ajax so if someone could help me out with this it would be most appreciated.

 

warm regards, Shaun

Link to comment
Share on other sites

This is how I would do it:

 

First, make a php script that will return the textareas based on $_GET. When you click "Click here for the code", have it run a function that will ask for send a request to your php script and then put the results in the area that you want the textareas.

 

Example code:

 

function ajax_init()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
return xmlHttp;
}

function grab_code()
{
var xmlHttp = ajax_init();
xmlHttp.open("GET","yourphpscript.php?get=",true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState==4) {
		document.getElementById("yourdiv").innerHTML=xmlHttp.responseText;
		}
	}
}

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.