1

So I like to append data(JSON) I received from the server to new pop up window. I tried what other people already posted but none of them actually works.

$.ajax
    ({
        url: "/receiveData",
        type: "POST",
        contentType: "application/json; charset=UTF-8",
        data:myJSON,
        dataType: "json",
        success: handledata
    });

so I have this ajax call and handle data

This is what i have on handledata function and I like to append this to specific id called "user" in open.html

var newin = window.open("open.html");
$(newin.document.body).ready(function() {
    //$(newin.document.body).append("<tr>"+ "Hello"+ "<tr>")
        newin.alert("hello");
});
이재찬
  • 56
  • 7

1 Answers1

0

You are thinking http request in a wrong way.
When you call window.open() the next window does not have any data from the existing window. It's a new js instance.

The solution is to past data in url as query parameter, eg: "open.html?data="+queryStr, and then send http call from <body onload="/* Your ajax call here */"> on open.html page.

There is how to encode json string:

function encode(queryStr) {
  return b.split(' ').map(i => encodeURIComponent(i)).join('+').replace(/'/g, "%27").replace(/"/g, "%22");
}

There is how to retrieve query string from url: How can I get query string values in JavaScript?

FisNaN
  • 2,517
  • 2
  • 24
  • 39
  • thx didn't think about putting ajax call on new popup window. Didn't really used the method you provided but it did solve my problem Thx a lot ! – 이재찬 Mar 09 '18 at 12:24