discern Posted September 25, 2007 Share Posted September 25, 2007 I have a large table of members. In each row is a checkbox. Each <tr> has an id of member$id (generated in PHP - ie <tr id='member635'>). I have an AJAX script that works perfectly on the testing server, but as soon as I upload my changes, Firefox stops working. I have an environment check in the ajax_init script that looks like this... function fetchAddress() { var loc; if (window.location.hostname == 'testingServerName') { loc = 'http://testingServerName/path/to/ajax/scripts/'; } else { loc = 'http://liveServerName/path/to/ajax/scripts/'; } return loc; } In the functions called by <input type='checkbox' onmouseup='changePosition();' /> the database is updated and the background of the row turns green or gray to let you know which direction the switch was thrown. The function looks like this... function changePosition(id) { var loc; loc = fetchAddress(); loc += "change_position.php?member_id=" + id; // Prints to a div called ajax_error // document.getElementById('ajax_error').innerHTML=loc; try { xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} xmlhttp.onreadystatechange = trigger1; xmlhttp.open("POST", loc); xmlhttp.send(null); } function trigger1() { if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { var response = xmlhttp.responseText; var update = []; update = response.split('||'); document.getElementById(update[0]).style.background=update[1]; document.getElementById(update[0]).style.color=update[2]; document.getElementById('ajax_error').innerHTML=update[3]; } } The change_position.php script outputs the proper || separated string. I know that Firefox prevents remote url javascript calls, but I'm quite sure that this is calling to the server that the script originates from. Any ideas? Quote Link to comment Share on other sites More sharing options...
discern Posted September 25, 2007 Author Share Posted September 25, 2007 Changing from POST to GET works in FF, but then breaks IE. Quote Link to comment Share on other sites More sharing options...
discern Posted September 25, 2007 Author Share Posted September 25, 2007 It's like I'm talking to myself. Anyway, I hope my problems helps someone else. What I did was change the try-catch from try { xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} to try { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest() method = 'GET'; } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); method= 'POST'; } } catch (e) {} And used the method variable in the xmlhttp.open. Problem solved. Hope it helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.