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
https://forums.phpfreaks.com/topic/141237-swapping-with-ajax-and-php/
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>

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.