Welcome Guest, Not a member yet? Register   Sign In
A simple ajax question.
#1

[eluser]cip6791[/eluser]
Hello,

I have a small issue with something I'm trying to do.


This is in my view. Not sure if this is the proper way to do this. I'm basically getting the content of the website for the home page. For each of the results I want a button that will get a little additional info for each item in a different div. The code works if I leave xmlhttp.open("GET","http://mysite.com/index.php/home/show/9/comm", true); the way it is. Since I need the id and the category in the url (9/comm) I tried doing this xmlhttp.open("GET","http://mysite.com/index.php/home/show/<?php echo $homeitem->id; ?>/<?php echo $homeitem->cat; ?>", true); but that doesn't work. Any help is appreciated. Is it ok to load the loadXMLDoc function for each of the items? Thank you.

Code:
<?php foreach($sqlquery->result() as $homeitem; ?>
<p>&lt;?php echo $homeitem->name; ?&gt;</p>

|script type="text/javascript"|
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv")[removed]=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://mysite.com/index.php/home/show/9/comm", true);
xmlhttp.send();
}
|/script|
<button>Change</button>
<php endforeach; ?&gt;

<div id="myDiv">Change this!</div>
#2

[eluser]TheFuzzy0ne[/eluser]
Check the page source and ensure that those variables are being printed as expected.
#3

[eluser]cip6791[/eluser]
Thanks for the reply!

I actually passed the id in the
Code:
<button>Change</button>
and it worked.




Theme © iAndrew 2016 - Forum software by © MyBB