Hallo,
ich habe 3 Dateien.
http.js
client01.html
api.php
hier möchte ich dass es so ist, wenn ich auf Click 1 klicke, dass Inhalt von api.php?id=e1 in <div id="msge1"></div> gezeigt wird und wenn ich auf Click 2 klicke, dass Inhalt von api.php?id=e2 in <div id="msge2"></div> gezeigt wird. Abe solche Einträge können beliebig sein.
Könnt ihr sagen, wie ich es so machen kann?
Danke!!
ich habe 3 Dateien.
http.js
Code:
var Http = {
get: function(uri, callback, onrequest, onresponse) {
try {
var http = Http.createInstance();
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200 && callback) {
callback(http.responseText);
if (onresponse) onresponse();
}
return true;
};
if (onrequest) onrequest();
http.open("GET", uri, true);
http.send(null);
}
catch(e) {
window.alert("Http.get: " + e.toString());
}
return false;
},
createInstance: function() {
var o = null;
if (!!window.XMLHttpRequest) {
try { o = new XMLHttpRequest(); } catch (e) { o = null; }
}
else if (!!window.ActiveXObject) {
try {o = new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch (e) {
try {o = new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {
try {o = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try { o = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
try { o = new ActiveXObject("MSXML.XMLHTTP"); } catch (e) {
try { o = new ActiveXObject("MSXML3.XMLHTTP"); } catch (e) { o = null; }
}
}
}
}
}
}
return o;
}
};
client01.html
Code:
<html>
<head>
<title> Rest Client</title>
<script type="text/javascript" src="http.js"></script>
<script type="text/javascript">
function callServer(id) {
Http.get("api.php?id=" + id, callback)
}
function callback(response) {
var div = document.getElementById("msg");
div.innerHTML = response;
}
</script>
</head>
<body>
<h2> Test Client</h2>
<span onclick="callServer('e1');">Click 1</span>
<div id="msge2"></div>
<span onclick="callServer('e2');">Click 2</span>
<div id="msge1"></div>
</body>
</html>
api.php
Code:
<?php
print("Hello ".$id);
?>
hier möchte ich dass es so ist, wenn ich auf Click 1 klicke, dass Inhalt von api.php?id=e1 in <div id="msge1"></div> gezeigt wird und wenn ich auf Click 2 klicke, dass Inhalt von api.php?id=e2 in <div id="msge2"></div> gezeigt wird. Abe solche Einträge können beliebig sein.
Könnt ihr sagen, wie ich es so machen kann?
Danke!!


Comment