Jump to content

swapping with ajax and php


littlehelp

Recommended Posts

ok i have information from a database that i wish to switch between there are 6 items on the bottom of the page that onclick the top item (it is alone) needs to be updated to show the content of the item that is selected. I just need an example of taking the information from a db and switching the content of the top item . so therefor items 1 2 3 4 5 6 are on the bottom with a pic of them and then the pic is clicked and it goes up top to be shown off with basic information. I hope i have explained this good enough, i am currently working on the code for it but am struggling fiercely with it, any examples would be greatly appreciated.(i can do the php easily enough only the ajax is making me go crazy)

 

Thanks in advance for any help.

Link to comment
Share on other sites

use this in your onclick event

 

as onclick="sndReq('mydivthingymebob','pointstomyphp.php?thisvar=something')"

 

:)

<script>
function createRequestObject() { 
  var ro; 
  var browser = navigator.appName; 
  if(browser == "Microsoft Internet Explorer"){ 
    ro = new ActiveXObject("Microsoft.XMLHTTP"); 
  }else{ 
    ro = new XMLHttpRequest(); 
  } 
  return ro; 
} 
var http = createRequestObject(); 
var returnDiv 
function sndReq(divRet,file) { 
  var date = new Date();
  var timestamp = date.getTime();
  returnDiv = divRet; 
  http.open('get', file+'&time='+timestamp); 
  http.onreadystatechange = handleResponse; 
  http.send(null); 
} 
function handleResponse() { 
  if(http.readyState == 4){ 
    var response = http.responseText; 
    document.getElementById(returnDiv).innerHTML = response; 
  } 
}
function resetdefault(a,b)
{
  document.getElementById(a).innerHTML = document.getElementById(b).innerHTML;
}
</script>

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.