Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using return false

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I'm having issues with setting up a function that executes an ajax statement within, but doesn't go past it, to return false.

Example Ajax function:
Code:
function myAjax(url,method,id){
	var xmlhttp=false; 
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e) {
		try {
			xmlhttp = new
			ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open(method, url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==1) {
			document.getElementById('status').style.display = '';
		}
		if (xmlhttp.readyState==4) {
			document.getElementById('status').style.display = 'none';
			var content = xmlhttp.responseText;
			if( content ){
				document.getElementById(id).innerHTML = content;
			}
		}
	}
	xmlhttp.send(null);
	xmlhttp.send('');
	return;
}
My separate function:
Code:
function loadItUp(fileid){
	NewWindow('go.php?doc='+fileid,'document'+fileid,'500','380','no','center');
	refreshDocuments();
	return false;
}

function refreshDocuments(){
	myAjax('do.php?docs','GET','doclist');
}
And this is a sample link:
Code:
<a href="go.php?doc=6" target="_blank" onClick="return loadItUp('6');">open doc 6</a>

What this code is supposed to do is open a new window with the given URL and re-load some information in the current window with the AJAX script.

What it ends up doing is Opening the new window, reloading my content, and then opening another window (using target _blank) just like the return false didn't even work.

Is there something wrong? Why is it not getting past my AJAX method?

This might help: I'm constantly getting this error in my Error Console:

Error: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: :: myAjax :: line 148" data: no]

(Line 148 being: xmlhttp.send('');)

I don't know what it means. I had to put it in there because it wasn't working in some browser... I can't remember which, maybe IE or Safari.

_______________
_brian.
 
Ok, I figured it out. I didn't realize "return" was not important to the functionality of the Ajax. I removed it and it works just like a normal function. Duh me...

_______________
_brian.
 
Well it was only part of the solution. i'm still getting that weird error code. I've googled it and seems like a lot of people experience it, but couldn't find any decent solutions.

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top