?
Solved

JS problem (Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED))

Posted on 2011-03-22
13
Medium Priority
?
4,502 Views
Last Modified: 2012-05-11
I am have a script that runs fine when included in a single script file loaded into the browser, i have changed the script so that it has a parent script that pulls in the body of the code via a function, so that updates do not rely on the user updating the script.

the script is running as it should up to the point where it should send the data to the database, i am then getting this error.

Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED)

code for this is below

ps. since posting this question i have tired thsi in a single script, and got a different error.

text/html (NS_ERROR_DOM_BAD_URI)

this made me realise i have left out an important bit of information, when it was working as a single script, it was using a Grease monkey propritory function

GM_xmlhttpRequest

to send the data... this meant the script would only work correctly in firefox, and does not have cross browser support, hence the change to the new code...

can anybody please help with this.. Thank You
var req = false;
  if (window.XMLHttpRequest) {
    try {      req = new XMLHttpRequest();    } catch (e) {      req = false;    }
  } else {
    alert('no window.xmlhttprequest');
  }
  if (req) {
    req.open('GET', urlSubmit, false);
    req.setRequestHeader('User-Agent','XMLHTTP/1.0');
   req.onreadystatechange = function(responseDetails) {
  var errMsgElem = document.getElementsByClassName('description');  
  var errMsg = errMsgElem[0];
  if(responseDetails.status == 200) {
   if(responseDetails.responseText == "OK") { errMsg.innerHTML += " // X2: <span style='color: rgb(10, 255, 10);'>OK SAM Updated.</span>"; } 
     else { errMsg.innerHTML += " // X2: <span style='color: rgb(255, 10, 10);'>" + responseDetails.responseText + "</span>"; }   
  } else { errMsg.innerHTML += " // X2: <span style='color: rgb(255, 10, 10);'>" + responseDetails.status + " - " + responseDetails.statusText + "</span>"; }
    }
    req.send();
  } else {    alert('Sorry, your browser does not support XMLHTTPRequest objects.');  }

Open in new window

0
Comment
Question by:QuinnDester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35198102
Show where and how you call it

What does urlSubmit look like?
The code you posted looks ok and should not give any errors
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35206641
the URL works, if i copy it into the browser address bar its accepted and the database is updated,

its just a normal GET url, ip adress with Value pairs tagged on

eg

123.123.123.123/listener.aspx?value=value&thisvalue=thisvalue
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35206672
full script code below
// ==UserScript==
// @name           SFC (SAM) (X2)
// @include http://uni2.playstarfleetextreme.com/*
// @include http://starfleet-fb-e-uni2.bluefrogsrv.com/*
// ==/UserScript==

var playerNameElem, playerName, rank
var planet, planetNameElem, planetName;
var allianceNameElem, allianceName;
var moon, moonNameElem, moonName;
var coordsElem, coords;
var slot = 1;
var urlSubmit = "", aCls = "";
var urlSearch = "";
var svAddr = "http://109.123.97.130/sfc_web_v1/";
var activate_p = document.URL.match(/activate_planet=([0-9]*)/);
var current_p = document.URL.match(/current_planet=([0-9]*)/);
var planet_id = "";

coordsElem = document.getElementsByClassName('current_solar_system');
coords = coordsElem[0].textContent.match(/\d{1,2}:\d{1,3}/g);

urlSubmit = svAddr + "listener.ashx?coords=" + coords;

if(activate_p) {
	planet_id = activate_p[1];
}
else if(current_p) {
	planet_id = current_p[1];
}

for(var slot = 1; slot < 16; slot++) {
	planet = document.getElementById('planet_' + slot);
	planetNameElem = planet.getElementsByClassName('name');
    if(planet.getElementsByClassName('activity').length>0) {
  var planetActivity = planet.getElementsByClassName('activity')[0].textContent ;
 
 }
	planetName = planetNameElem[0].textContent.replace(/\((\*|\d{1,2} min)\)/g, "").replace("[ Rename ]", "").trim();
	playerNameElem = planet.getElementsByClassName('player');
	//playerName = playerNameElem[0].textContent.replace(/\([viInNd!s]*\)/g, "").replace(/#[\d,]*/g, "").trim();
	playerName = playerNameElem[0].getElementsByTagName('span')[0] != null ? playerNameElem[0].getElementsByTagName('span')[0].childNodes[0].textContent.trim() : '';
    if(playerNameElem[0].getElementsByTagName('span')[0]!=null  ) {
      if(playerNameElem[0].getElementsByTagName('span')[0].childNodes[1].textContent[0]!='(')
       rank = trim(playerNameElem[0].getElementsByTagName('span')[0].childNodes[1].textContent);
      else
       rank = trim(playerNameElem[0].getElementsByTagName('span')[2].textContent);
 }

	
	allianceNameElem = planet.getElementsByClassName('alliance');
	allianceName = allianceNameElem[0].textContent.trim();

	if(playerName != "") {
		urlSubmit = urlSubmit + "&name" + slot + "=" + fixedEncodeURIComponent(planetName);
		urlSubmit = urlSubmit + "&player" + slot + "=" + fixedEncodeURIComponent(playerName);
		urlSubmit = urlSubmit + "&alliance" + slot + "=" + fixedEncodeURIComponent(allianceName);
		urlSubmit = urlSubmit + "&activity" + slot + "=" + fixedEncodeURIComponent(planetActivity);
        urlSubmit = urlSubmit + "&rank" + slot + "=" + fixedEncodeURIComponent(rank);
		moon = document.getElementById('planet_' + slot + 'm');
		if(moon != null) {
			moonNameElem = moon.getElementsByClassName('name');
			moonName = moonNameElem[0].textContent.replace(/\((\*|\d{1,2} min)\)/g, "").replace("[ Rename ]", "").trim();
			urlSubmit = urlSubmit + "&moon" + slot + "=" + fixedEncodeURIComponent(moonName);
		}
		
		urlSearch = svAddr + "search.aspx?action=search&by=name&p=" + fixedEncodeURIComponent(playerName);
		urlSearch = urlSearch + "&planet_id=" + planet_id;
		if(playerNameElem[0].innerHTML.search("not_attackable") == -1) {
			playerNameElem[0].getElementsByClassName("attackable")[0].innerHTML = playerNameElem[0].getElementsByClassName("attackable")[0].innerHTML.replace(playerName, "<a class='attackable' href='" + urlSearch + "' target='_blank'>" + playerName + "</a>");
		}
		else {
			playerNameElem[0].getElementsByClassName("not_attackable")[0].innerHTML = playerNameElem[0].getElementsByClassName("not_attackable")[0].innerHTML.replace(playerName, "<a class='not_attackable' href='" + urlSearch + "' target='_blank'>" + playerName + "</a>");
		}
	}
}


var req = false;
  if (window.XMLHttpRequest) {
    try {      req = new XMLHttpRequest();    } catch (e) {      req = false;    }
  } else {
    alert('no window.xmlhttprequest');
  }
  if (req) {
    req.open('GET', urlSubmit, false);
    req.setRequestHeader('User-Agent','XMLHTTP/1.0');
    req.onreadystatechange = function(responseDetails) {
  var errMsgElem = document.getElementsByClassName('description');  
  var errMsg = errMsgElem[0];
  if(responseDetails.status == 200) {
   if(responseDetails.responseText == "OK") { errMsg.innerHTML += " // X2: <span style='color: rgb(10, 255, 10);'>OK SAM Updated.</span>"; } 
     else { errMsg.innerHTML += " // X2: <span style='color: rgb(255, 10, 10);'>" + responseDetails.responseText + "</span>"; }   
  } else { errMsg.innerHTML += " // X2: <span style='color: rgb(255, 10, 10);'>" + responseDetails.status + " - " + responseDetails.statusText + "</span>"; }
    }
    req.send();
  } else {    alert('Sorry, your browser does not support XMLHTTPRequest objects.');  }


function fixedEncodeURIComponent (str) {  
	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').  
                        replace(/\)/g, '%29').replace(/\*/g, '%2A');  
} 
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35207566
I am confused

You sad: When it was working it was a greasemonkey script.

Now it is not?

And is the URL from a different domain than the domain you are on?
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35208216
that is the script that isnt working it will work if i use the GM_httpRequest like below
// ==UserScript==
// @name           SFC (SAM) (X2)
// @include http://uni2.playstarfleetextreme.com/*
// @include http://starfleet-fb-e-uni2.bluefrogsrv.com/*
// ==/UserScript==

var playerNameElem, playerName, rank
var planet, planetNameElem, planetName;
var allianceNameElem, allianceName;
var moon, moonNameElem, moonName;
var coordsElem, coords;
var slot = 1;
var urlSubmit = "", aCls = "";
var urlSearch = "";
var svAddr = "http://109.123.97.130/sfc_web_v1/";
var activate_p = document.URL.match(/activate_planet=([0-9]*)/);
var current_p = document.URL.match(/current_planet=([0-9]*)/);
var planet_id = "";

coordsElem = document.getElementsByClassName('current_solar_system');
coords = coordsElem[0].textContent.match(/\d{1,2}:\d{1,3}/g);

urlSubmit = svAddr + "listener.ashx?coords=" + coords;

if(activate_p) {
	planet_id = activate_p[1];
}
else if(current_p) {
	planet_id = current_p[1];
}

for(var slot = 1; slot < 16; slot++) {
	planet = document.getElementById('planet_' + slot);
	planetNameElem = planet.getElementsByClassName('name');
    if(planet.getElementsByClassName('activity').length>0) {
  var planetActivity = planet.getElementsByClassName('activity')[0].textContent ;
 
 }
	planetName = planetNameElem[0].textContent.replace(/\((\*|\d{1,2} min)\)/g, "").replace("[ Rename ]", "").trim();
	playerNameElem = planet.getElementsByClassName('player');
	//playerName = playerNameElem[0].textContent.replace(/\([viInNd!s]*\)/g, "").replace(/#[\d,]*/g, "").trim();
	playerName = playerNameElem[0].getElementsByTagName('span')[0] != null ? playerNameElem[0].getElementsByTagName('span')[0].childNodes[0].textContent.trim() : '';
    if(playerNameElem[0].getElementsByTagName('span')[0]!=null  ) {
      if(playerNameElem[0].getElementsByTagName('span')[0].childNodes[1].textContent[0]!='(')
       rank = trim(playerNameElem[0].getElementsByTagName('span')[0].childNodes[1].textContent);
      else
       rank = trim(playerNameElem[0].getElementsByTagName('span')[2].textContent);
 }

	
	allianceNameElem = planet.getElementsByClassName('alliance');
	allianceName = allianceNameElem[0].textContent.trim();

	if(playerName != "") {
		urlSubmit = urlSubmit + "&name" + slot + "=" + fixedEncodeURIComponent(planetName);
		urlSubmit = urlSubmit + "&player" + slot + "=" + fixedEncodeURIComponent(playerName);
		urlSubmit = urlSubmit + "&alliance" + slot + "=" + fixedEncodeURIComponent(allianceName);
		urlSubmit = urlSubmit + "&activity" + slot + "=" + fixedEncodeURIComponent(planetActivity);
        urlSubmit = urlSubmit + "&rank" + slot + "=" + fixedEncodeURIComponent(rank);
		moon = document.getElementById('planet_' + slot + 'm');
		if(moon != null) {
			moonNameElem = moon.getElementsByClassName('name');
			moonName = moonNameElem[0].textContent.replace(/\((\*|\d{1,2} min)\)/g, "").replace("[ Rename ]", "").trim();
			urlSubmit = urlSubmit + "&moon" + slot + "=" + fixedEncodeURIComponent(moonName);
		}
		
		urlSearch = svAddr + "search.aspx?action=search&by=name&p=" + fixedEncodeURIComponent(playerName);
		urlSearch = urlSearch + "&planet_id=" + planet_id;
		if(playerNameElem[0].innerHTML.search("not_attackable") == -1) {
			playerNameElem[0].getElementsByClassName("attackable")[0].innerHTML = playerNameElem[0].getElementsByClassName("attackable")[0].innerHTML.replace(playerName, "<a class='attackable' href='" + urlSearch + "' target='_blank'>" + playerName + "</a>");
		}
		else {
			playerNameElem[0].getElementsByClassName("not_attackable")[0].innerHTML = playerNameElem[0].getElementsByClassName("not_attackable")[0].innerHTML.replace(playerName, "<a class='not_attackable' href='" + urlSearch + "' target='_blank'>" + playerName + "</a>");
		}
	}
}

GM_xmlhttpRequest({
    method: 'GET',
    url: urlSubmit,
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'text/html',
    },
    onload: function(responseDetails) {
		var errMsgElem = document.getElementsByClassName('description');
		
		var errMsg = errMsgElem[0];
		if(responseDetails.status == 200) {
			if(responseDetails.responseText == "OK") {
				errMsg.innerHTML += " // X2: <span style='color: rgb(10, 255, 10);'>OK SAM Updated.</span>";
			}
			else {
				errMsg.innerHTML += " // X2: <span style='color: rgb(255, 10, 10);'>" + responseDetails.responseText + "</span>";
			}
			
		}
		else {
			errMsg.innerHTML += " // X2: <span style='color: rgb(255, 10, 10);'>" + responseDetails.status + " - " + responseDetails.statusText + "</span>";
		}
    }
});

function fixedEncodeURIComponent (str) {  
	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').  
                        replace(/\)/g, '%29').replace(/\*/g, '%2A');  
} 
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35208373
So what is the question? You just want to change the request or what? And why if it already works with the GM
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35208434
because it doesnt have cross browser support using GM, i also want to split the body of the code into an external file, this will not work using the GM
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35208719
But sites will not work cross domain in any browser anyway
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35209693
but this does work across domains, to get this to work accross domains all you need to do is add a header

context.Response.AddHeader("Access-Control-Allow-Origin", "*");

this allows the script to comunicate across domains
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 35209977
This allows Fx3.5+ and Safari 4+ to access the server that implements the above header, however CORS using XHR is not implemented in IE8 which needs XDR instead. So you will need to use libraries that has implemented these to run this in both IE and Fx.

Here is an example of both http://www.leggetter.co.uk/2010/03/12/making-cross-domain-javascript-requests-using-xmlhttprequest-or-xdomainrequest.html
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35217388
right i have found the problem, windows basic authentication stops it from working, the the GM method works with windows basic authentication.


is there a way of making the generic XMLHttpRequest work with windows authentication
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 35217403
this is a completely different question now, i will award points for the information concerning IE8, as i didnt knwo about this and it would have cropped up as a question later.. and open a new question concerning authentication.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35217558
http://msdn.microsoft.com/en-us/library/ms536648%28v=vs.85%29.aspx

open Method
Assigns method, destination URL, and other optional attributes of a pending request.
Syntax
    object.open(sMethod, sUrl [, bAsync] [, sUser] [, sPassword])

Parameters
   sMethod       Required. String that specifies the HTTP method used to open the connection: such as GET, POST, or HEAD. This parameter is not case-sensitive.
   sUrl       Required. String that specifies either the absolute or a relative URL of the XML data or server-side XML Web services.
   bAsync       Optional. Variant that specifies true for asynchronous operation (the call returns immediately), or false for synchronous operation. If true, assign a callback handler to the onreadystatechange property to determine when the call has completed. If not specified, the default is true.
    Performance Note   When bAsync is set to false, send operations are synchronous, and Windows Internet Explorer does not accept input or produce output while send operations are in progress. Therefore, this setting should not be used in situations where it is possible for a user to be waiting on the send operation to complete.
   sUser       Optional. Variant that specifies the name of the user for authentication. If this parameter is null ("") or missing and the site requires authentication, the component displays a logon window.
   sPassword       Optional. Variant that specifies the password for authentication. This parameter is ignored if the user parameter is null ("") or missing.

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question