Shaun Posted April 23, 2008 Share Posted April 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
Money Posted April 23, 2008 Share Posted April 23, 2008 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; } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.