Jump to content

[SOLVED] AJAX works perfectly... until I upload.


discern

Recommended Posts

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?

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.