私はCodeigniterを使用していますが、機能が少し残っているようです。私はhttp://mysite.com/index.php/home/show/9/commからmyDiv divの中にコンテンツをロードする複数の要素にajax関数を追加する
<?php foreach($sqlquery->result() as $item): ?>
<h1><?php echo $item->name; ?></h1>
<button onlick="loadXMLDoc()">Change</button>
<?php endforeach; ?>
<div id="myDiv">This content will change when button is pressed!</div>
:私はホームページのタイトルのリストを持っています。ビューのショーは、URLにあるもののid(9)とどのようなカテゴリ(COMM)に応じて、データが表示されます。
<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").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://mysite.com/index.php/home/show/9/comm ", true);
xmlhttp.send();
}
</script>
<button onlick="loadXMLDoc()">Change</button>
私はforeachの中に機能を追加しようとしたGET URLを変更しますが、それを得ることができませんでした仕事に:あなたは、loadXMLドキュメント関数にあなたからそれを呼び出すように関係なく、ハードコーディングされたアイテムのIDをしました
xmlhttp.open("GET","http://mysite.com/index.php/home/show/<? echo $item->id; ?>/<? echo $item->cat; ?> ", true);