Ajax stopt met werken
Ik had eerst een ajax functie gemaakt met javascript maar toen heb ik die geprobeerd te perfectioneren zodat ik hem vaker kan gebruiken maar nu doet hij helemaal niets meer.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function xmlhttpPost(strURL,Result_id,Form_name,Media_id,Input_id) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText, Result_id);
}
}
self.xmlHttpReq.send(getquerystring(Form_name,Media_id,Input_id));
}
function getquerystring(Form_name,Media_id,Input_id) {
var form = document.forms[Form_name];
var word = form.Input_id.value;
qstr = 'value=' + escape(word) + '&media_id=' + Media_id; // NOTE: no '?' before querystring
return qstr;
}
function updatepage(str,Result_id){
document.getElementById(Result_id).innerHTML = str;
}
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText, Result_id);
}
}
self.xmlHttpReq.send(getquerystring(Form_name,Media_id,Input_id));
}
function getquerystring(Form_name,Media_id,Input_id) {
var form = document.forms[Form_name];
var word = form.Input_id.value;
qstr = 'value=' + escape(word) + '&media_id=' + Media_id; // NOTE: no '?' before querystring
return qstr;
}
function updatepage(str,Result_id){
document.getElementById(Result_id).innerHTML = str;
}
Dit is de originele code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}
function getquerystring() {
var form = document.forms['playlist'];
var word = form.playlist_id.value;
var media = form.media_id.value;
qstr = 'playlist=' + escape(word) + '&media_id=' + media; // NOTE: no '?' before querystring
return qstr;
}
function updatepage(str){
document.getElementById("playlist_result").innerHTML = str;
}
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}
function getquerystring() {
var form = document.forms['playlist'];
var word = form.playlist_id.value;
var media = form.media_id.value;
qstr = 'playlist=' + escape(word) + '&media_id=' + media; // NOTE: no '?' before querystring
return qstr;
}
function updatepage(str){
document.getElementById("playlist_result").innerHTML = str;
}
Zo roep ik hem aan:
Code (php)
1
<input type="button" name="add" value="Toevoegen" onclick='JavaScript:xmlhttpPost("functions/playlist.php","playlist_result","playlist","<?php echo $media_id; ?>","playlist_id")' />
iemand?
Installeer Firebug in Firefox en kijk wat voor foutmelding hij geeft. Aan 'er gaat iets fout' hebben wij en jij niets.