Forum Moderators: open
i have data in a mysql db that is simply catalgued by an id integer. i would like to creat an html navigation (a basic set of links) that would use ajax to load data into a div.
this is for simple content management system for clients sites.
how might I alter this code so that I don't have to add a hidden input, but rather include the id in the actual link (the <a href="" some javascript>link 1</a>)
here is my current code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<title>Customer Account Information</title>
<script type="text/javascript">
var url = "GetCustomerData.php?id="; // The server-side script
function handleHttpResponse() {
if (http.readyState == 4) {
if(http.status==200) {
var results=http.responseText;
document.getElementById('divCustomerInfo').innerHTML = results;
}
}
}
function requestCustomerInfo() {
var sId = document.getElementById("txtCustomerId").value;
http.open("GET", url + escape(sId), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (!xmlhttp){
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
</script>
</head>
<body><a href="javascript:requestCustomerInfo('1')">request 1</a>
<input type="hidden" value="1" id="txtCustomerId"><div id="divCustomerInfo"></div>
</body>
</html>
function requestCustomerInfo(sId) {
if(! sId ) { return false; } // to prevent sending bad data to script
http.open("GET", url + escape(sId), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function requestCustomerInfo(id) {
if(! id ¦¦ id == ''){return}
var URL = "GetCustomerData.php?id="+id+"&"+new Date().getTime(); //time stops cache by browser
var container = document.getElementById("divCustomerInfo");
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
request.open("GET", URL, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
container.innerHTML = request.responseText;
}
}
request.send(null);
}