0

I'm trying to fetch the outputed text from a website. If the website displays true for a user having a certain assetid, it will display the userid. If the website displays false, it will skip that user and move to the next.

I'm using the following code to process the instructions listed above:

var countedOwners = 0, nameOfOwner;
document.writeln("<h1>Found owners</h1>");

var setUp = function() { var assetID = prompt("Enter asset ID in the input box which you would like to search for","1285307");

if (assetID != null && assetID.length > 5 && assetID.length < 10 && !isNaN(assetID)) {

var speed = prompt("How fast would you like to scan in milliseconds? - Do not type under 200 milliseconds for overload issues.");

if (speed != null) {

if (speed > 200) {
var userID = prompt("What ID would you like to start from(will increase by 1 every time)) Default: 1", "1");
if (userID != null && !isNaN(userID)) {
itemScanner(assetID, speed, userID);
}

} else {

itemScanner();

}
}
}};


function createLink(userID, speed) {
var a = document.createElement('a');
var linkText = document.createTextNode("http://www.roblox.com/User.aspx?ID=" + (userID - 1));
a.appendChild(linkText);
a.title = "my title text";
a.href = "http://www.roblox.com/User.aspx?ID=" + (userID - 1);
document.body.appendChild(a);
//creating speed increaser...
var btn = document.createElement("BUTTON");  
var t = document.createTextNode("Increase speed?"); 
btn.appendChild(t);  
document.body.appendChild(btn); 
btn.onclick = function(){ var newSpeed = prompt("Your current speed is " + speed + " milliseconds. \n Input what speed you would like it to run at below.","300")
speed = newSpeed;
};
}

var itemScanner = function(assetID, speed, userID) {
setInterval(function() {
$.ajax({
url: "https://api.roblox.com/ownership/hasasset?userId=" + userID + "&assetId=" + assetID,
type: 'GET',
}).success(function(Data) {
var pageInfo = Data;
if (pageInfo === true) {
$.get("http://api.roblox.com/Users/" + userID, function(json) {
nameOfOwner = json.Username;
countedOwners = countedOwners + 1; 
console.info("Discovered owner of the item, the user's ID is " + userID + "." + "The name is " + nameOfOwner); 
console.info("Concurrent discovered owners - " + countedOwners + ".");
document.write("<h4>Found an Owner ("+ "User ID = " + (userID - 1) + ")" + " Owner Name: " + nameOfOwner + "." + "</h4>");
createLink(userID, speed);
});
}
userID++;
});
}, speed);
}


setUp(); 

However when I run it through the Google Chrome console on Roblox.com, it displays the error:

XMLHttpRequest cannot load https://api.roblox.com/ownership/hasasset?userId=undefined&assetId=undefined. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.roblox.com' is therefore not allowed access. The response had HTTP status code 503.

How can I resolve this?

Lizzy Met
  • 1
  • 2
  • this happens because you have an external address where you want to load smth - in your case i think its a problem between www.roblox.com and api.roblox.com. Maybe you need a .htaccess file here – messerbill Dec 22 '15 at 12:54
  • I didn't think that would be a problem, as api.roblox.com is a subdomain of roblox.com.. – Lizzy Met Dec 22 '15 at 12:55
  • whats the host? is it roblox.com? – messerbill Dec 22 '15 at 12:56
  • Yes, roblox.com is the host. – Lizzy Met Dec 22 '15 at 12:57
  • hm, it looks that your host is offline - `503 Service Unavailable The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.[80]` could this be the reason? if i try to visit your page, its online.... – messerbill Dec 22 '15 at 13:00
  • I wasn't aware that the site is offline... I can access it without any issues (meaning it's online) - could there be a typo/error in the script causing this? – Lizzy Met Dec 22 '15 at 13:01
  • yes. I think its because of your https / http crossdomain. i am searching at the moment how to solve this – messerbill Dec 22 '15 at 13:02
  • does this help you? http://stackoverflow.com/questions/8414786/javascript-cross-domain-call-call-from-http-to-https – messerbill Dec 22 '15 at 13:18

1 Answers1

1

The resource that you're requesting has blocked requests from external domains and it does this by setting out a HTTP header, this header is Access-Control-Allow-Origin, by looking at the error message it appears there is no header setting which means it doesn't have Access-Control-Allow-Origin: * which if you're calling from a different domain you will need.

Here's a bit more on CORS a link

I've assumed you're not in control of the page you're trying to access which could be wrong, another solution could be to add that Access-Control-Allow-Origin: http://www.roblox.com to this web page.

Simon Houlton
  • 182
  • 1
  • 10
  • As I mentioned in a reply to messerbill, api.roblox.com is a subdomain of roblox.com rather than a different domain, therefore I thought it would be exempt from this issue. – Lizzy Met Dec 22 '15 at 13:10
  • just like i said - i bet its because of the http / https cross-domain - have a look here: http://stackoverflow.com/questions/8414786/javascript-cross-domain-call-call-from-http-to-https – messerbill Dec 22 '15 at 13:18
  • I don't believe I require https, would it resolve anything if I changed all of them to begin with http? – Lizzy Met Dec 22 '15 at 13:30
  • Hi Lizzy, that's a bit of a loaded question and will depend on the context. One thing I will say is I wouldn't recommend mixing secure and unsecure content because it will cause browsers to throw warnings. I'd pick a delivery mechanism and stick to it but I still don't think this will solve your error. – Simon Houlton Dec 22 '15 at 14:05