I have a .js document with AJAX and jQuery that pulls info from a PHP page with a loop.
My problem is that whenever I call the JS file from on PHP file's while loop the JavaScript only pulls the data from the top iteration and not the 2nd, 3rd, 5th or any other below the 1st data.
This is the JS file
var delete_group = function load_xml() {
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('status').innerHTML = xmlhttp.responseText;
}
}
var id = document.getElementsByClassName('id')[0].innerHTML
xmlhttp.open('POST', 'ajax/file.php?id='+id, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send()
}
$(document).ready( function pop_window() {
$('.delete_group').click( function show_window() {
$.fallr('show', {
content: 'Status: <div id="status"> </div>',
position: 'bottom',
buttons: {
button1: {text: 'Yes', danger: true, onclick: delete_group},
button2: {text: 'Cancel'}
},
content: '<p>Are you sure want to delete this?</p>'
+ 'Status: <div id="status"> </div>',
icon: 'error'
})
})
});
and this is the PHP cut of the while loop:
echo '<li>
<h4>'.$name.'</h4>
<div class="btn dropup">
<button data-toggle="dropdown" class="btn dropdown-toggle">
Options... <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="view.php?id='.$id.'">View</a></li>
<li><a href="file.php?id='.$id.'">Add Multiple Contacts</a></li>
<li class="divider"></li>
<li><a class="delete_group">Delete</a><p hidden class="id">'.$id.'</p></li>
</ul>
</div>
</li>'
If I activate the JavaScript and make the script do what it's suppose to do, it's going to call the 1st value from the 1st class='id'
How can I fix this and make document.getElementsByClassName loop and get the right value from the item that I want?
$.postor$.ajax$.post('url',{data1name:data1val,data2name:data2val},function(theAjaxResponse){do something with theAjaxResponse});