0

Here's the dilemma. I'm voting on these different reports on webpage #1 (http://www.blankmediagames.com/Trial/#start) and I'm trying to get a specific object called "data" from webpage #2 (http://www.blankmediagames.com/Trial/viewReport.php?id=1388499). However, when I use this code, it only returns the entire webpage.

var tempVar;
var reportPage = new XMLHttpRequest();
reportPage.open('GET', '/Trial/viewReport.php?id=1388499', true);
reportPage.onreadystatechange = function() {
   if (reportPage.readyState === 4)  { 
   tempVar = (reportPage.responseText);
  }
};
reportPage.send(null);

I am trying to grab the object called "data" from webpage #2 and store it in another variable while I'm on webpage #1. Is there any way I can do this?

This is basically what is found in webpage #2:

<!DOCTYPE html>
...
    <script>
            $(document).ready(function()
            {
                data = {"ReportID":"1388499","Username":"FatJellyBean","ReportFile":"Report1386875","Reason":"Gamethrowing","Appeal":"","Submitted":"Jun. 10, 2018 12:41 pm","numReports":2,"players":[{"username":"TooEzJukedBaited","ign":"ImJester","role":"SerialKiller","slot":1},{"username":"RISTR1K","ign":"Covfefe","role":"Doctor","slot":2},{"username":"balintka0607","ign":"William Phips","role":"Retributionist","slot":3},{"username":"JohnGotti","ign":"Karl Marx","role":"Veteran","slot":4},{"username":"Konrad4123","ign":"Pepe","role":"Escort","slot":5},{"username":"Celerian","ign":"Jeff","role":"Jester","slot":6},{"username":"foxesfan9","ign":"dabbingisnotcool","role":"Executioner","slot":7},{"username":"FatJellyBean","ign":"ifyoudonthitsubm","role":"Medium","slot":8},{"username":"GalaxyUnivern","ign":"Eliza Macbeth","role":"Godfather","slot":9},{"username":"Davve27","ign":"Katana","role":"Investigator","slot":10},{"username":"GayBobFaggyPants","ign":"Sarah Bishop","role":"Godfather","slot":11},{"username":"holysilman","ign":"Lil Tay","role":"Sheriff","slot":12},{"username":"pingvingen","ign":"Garfunkle","role":"Lookout","slot":13},{"username":"fefecute","ign":"Fefecute","role":"Framer","slot":14},{"username":"Frogers98","ign":"James Russel","role":"Jailor","slot":15}]};
                Trial.populateFilter(data);
                $
                                $('.reportedPlayer').html($('#FatJellyBean').next().html());
                $('#highlighter').show();
            });
            function highlight(elem,start,end)
            {
                var el=elem[0];
                var eln= (el.children.length > 0) ? el.lastChild : el.childNodes[0];
                var range=document.createRange();
                var sel=window.getSelection();
                start = (typeof start != 'undefined') ? start : 0;
                end = (typeof end != 'undefined') ? end : el.innerHTML.length;
                if(el.children.length > 0) start = end = 0;
                range.setStart(eln,start);
                range.setEnd(eln,end);
                sel.removeAllRanges();
                sel.addRange(range);
                el.focus();
            }
        </script>
...
</html>
Lord Nazo
  • 37
  • 1
  • 1
  • 6
  • where do you see this data object on page #2? Your best bet would be to use a json endpoint instead of hitting a full page, but if it's contained in a certain element, there are tricks to extracting data... –  Jun 26 '18 at 23:16

2 Answers2

0

It's possible to transfer one object to another page, but not through the method you are trying.

There are a few hacks where you can use the url params: How to pass javascript variables from one html page to other html page

However it's more recommended to build endpoints and an API to pass information around. This sort of architecture involves more work but solves your exact problem: How to pass javascript object from one page to other

Joseph Cho
  • 4,033
  • 4
  • 26
  • 33
-1

Sadly, the Same Origin Policy prevents data from being returned from other domains, including subdomains. You could try using JSONP, however.

Frex
  • 54
  • 2
  • You're not wrong, but the Same Origin Policy doesn't apply here because @Lord Nazo is getting data from the same domain. (e.g. blankmediagames.com) – Joseph Cho Jun 26 '18 at 23:21
  • Ah, you are correct, I read the URL's as subdomains for some reason – Frex Jun 26 '18 at 23:25