Problem with IE8 with ajax and alert
i have the following script.
everything works fine in ff, safari.
But in IE the alert "Du kannst pro Beitrag nur 1 x voten." is not showing
Browser Support Code
function voteFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
开发者_运维知识库 alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
var TYPE = document.getElementById('TYPE').value;
if(ajaxRequest.readyState == 4){
if (ajaxRequest.responseText == 'you voted allready'){alert('Du kannst pro Beitrag nur 1 x voten.')}
if (ajaxRequest.responseText != 'you voted allready'){
document.getElementById('cdm_play_video_votes').innerHTML= ajaxRequest.responseText;}
if (TYPE == 1 ){publishVideovote();}
if (TYPE == 2 ){publishImagevote();}
}
}
var videoid = document.getElementById('videoid').value;
var userid = document.getElementById('userid').value;
var queryString = "?function=vote&videoid=" + videoid + "&userid=" + userid ;
ajaxRequest.open("GET", "function.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
can anybody help me?
thanks a lot in advance
(removed original answer)
Ok, since the AJAX part works, and just the alert in the handler is failing I would look into the code there.
Using the ID "type", and referencing the value of that element with a variable of the same name smells like IE's global namespace pollution might be affecting your code.
try changing this line from:
var TYPE = document.getElementById('TYPE').value;
to:
var typeValue = document.getElementById('TYPE').value;
^^^^^^^^^
and then all references to it after wards.
Which of the alerts isn't showing? The code you posted contains two, so identifying which section of the code we're supposed to be focusing on would be helpful.
One very small thing that I noticed: You're missing a semi-colon at the end of the second alert - if (ajaxRequest.responseText == 'you voted allready'){alert('Du kannst pro Beitrag nur 1 x voten.')} - which may cause the problem (I'm not sure how picky IE8 is about that kind of thing).
精彩评论