grahama1970
Technical User
I am very new to ajax and javascript
I hacked together this 'working' example to dynamically spit out a movie embed into a div. The problem is that I have no idea what the 'gotchas' are when employing Ajax related solutions.
The Question:
Is there any more javascript related error correction that needs to be done ? I am a bit too new to expect the below to work in a real world scenario.
any help/advice is appretiated
g
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"<html xmlns="<head>
<title>rasmusExample.html</title>
<meta name="generator" content="BBEdit 8.0" />
<script type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'getmovie.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
</script>
</head>
<body>
<form>
<p>Pick a Movie:<br />
<select name="empty" onChange="sndReq(this.value)">
<option value="empty">Choose One</option>
<option value="boeing">boeing</option>
<option value="nike">nike</option>
<option value="levis">levis</option>
<option value="yamaha">yamaha</option>
</select>
</p>
</form>
<div id="foo">
</div>
</body>
</html>
I hacked together this 'working' example to dynamically spit out a movie embed into a div. The problem is that I have no idea what the 'gotchas' are when employing Ajax related solutions.
The Question:
Is there any more javascript related error correction that needs to be done ? I am a bit too new to expect the below to work in a real world scenario.
any help/advice is appretiated
g
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"<html xmlns="<head>
<title>rasmusExample.html</title>
<meta name="generator" content="BBEdit 8.0" />
<script type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'getmovie.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
</script>
</head>
<body>
<form>
<p>Pick a Movie:<br />
<select name="empty" onChange="sndReq(this.value)">
<option value="empty">Choose One</option>
<option value="boeing">boeing</option>
<option value="nike">nike</option>
<option value="levis">levis</option>
<option value="yamaha">yamaha</option>
</select>
</p>
</form>
<div id="foo">
</div>
</body>
</html>