0

I have the following code that is run when I press a button:

function document_preview_changes()
{
    var url = 'lib/chart-preview-embed.php';
    var data =
    {
        gamesrecord_id: gamesrecord_id,
        style_id: style_id,
        layout_id: layout_id,
        format_id: format_id,
        game_id: game_id,
        game_seo: game_seo,
        ten_bool: ten_bool,
        svg_bool: svg_bool,
        commandouter_table: commandouter_table
    }
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.addEventListener("load", reqListener);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.send(JSON.stringify(data));
}

function reqListener ()
{
    console.log(this.responseText);
}

I want to post the data to 'chart-preview-embed.php' and load the PHP file in a new window. However, nothing happens. (No errors either.) What am I doing wrong?

posfan12
  • 2,541
  • 8
  • 35
  • 57
  • 1
    I think you forgot to add an event listener to the xhr to listen for the load event https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest – chiliNUT Dec 25 '20 at 02:26
  • Okay, I added an event listener. I want to load the document in a new window however. – posfan12 Dec 25 '20 at 02:55
  • yeah just add the code to open it in a new window inside of the function – chiliNUT Dec 25 '20 at 02:55
  • Could you help with this? It is the part I don't understand. – posfan12 Dec 25 '20 at 02:57
  • 1
    I'm guessing you are getting back some html from your ajax request? You should do `console.log(this);` to see what all you are getting back. Once you have found whatever it is you want to display in a new window, this should help you out: https://stackoverflow.com/a/19078591/2079345 – chiliNUT Dec 25 '20 at 03:14
  • Is there no other way? I need users to be able to save the page (and CSS, images, etc.) to disk but you can't do that when generating the page using JavaScript. – posfan12 Dec 25 '20 at 07:50

0 Answers0