Making this code work with Firefox (AJAX Code)

Discussion in 'HTML & Website Design' started by AdvancedNoob, Aug 6, 2010.

  1. #1
    Hey, I wanna use this code to display now playing songs on my shoutcast server. But the thing is it doesnt work with firefox but it does with IE... usually its the other way around :p
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    
    <head>
    
    <title>Shoutcast Now Playing Using AJAX</title>
    
    <script language="javascript"  type="text/javascript">
    
    var url = "http://advancedvi.be:8000/7.html";
    
    
    
    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();
    
    http.open('GET', url);
    
    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(',');
    
    			if (update[1] == 1) {
    
    				document.getElementById('playing').innerHTML = update[6];
    
    			} else {
    
    				document.getElementById('playing').innerHTML = 'Server Offline.';
    
    			}
    
    		}
    
    	}
    
    }
    
    </script>
    
    </head>
    
    <body>
    
    <b>Currently Playing:</b> <div id="playing"></div>
    
    </body>
    
    </html>
    HTML:

     
    AdvancedNoob, Aug 6, 2010 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    541
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Hi,
    Possibly because of this line:
    if(response.indexOf(',' != -1)) {
    
    Code (markup):
    Try rewrite it as:
    if(response.indexOf(',') != -1) {
    Code (markup):
     
    hdewantara, Aug 7, 2010 IP
  3. oxidati0n

    oxidati0n Peon

    Messages:
    744
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Remember, if you're hosting it on another website to the "http://advancedvi.be:8000/7.html" then the browser won't allow the connection for XSS hacking issues. You can't make AJAX-based requests to third parties and manipulate the content as the request is signed to the user, not the server so it's considered hacking.
     
    oxidati0n, Aug 7, 2010 IP