0

I am trying to load a page inside a div using below code.

    $("#ReportDiv").load("../pages/Report.html", function (response, status, xhr) {
    if (status == "error") {
        $("#ReportDiv").html("Unable to load the page");
    }
});

It is simple load function which works great for normal URL. In this case, I am trying to pass querystring to the page with the below url.

"../pages/Report.html?SomeParam=true", 

This also works fine. But I am unable to read this value in Report.html page. Obviously "window.location" won't provide this querystring. And other than that, I can't figure out what other way I can try.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
jitendragarg
  • 945
  • 1
  • 14
  • 54
  • 1
    @mplungjan Because I am loading this page inside a DIV. So, window.location will still give me url of the calling page, not the one opened inside the Div. – jitendragarg Mar 07 '19 at 09:25
  • 2
    You would need to read the querystring values on the server side as no JS will be executed when the request to Report.html is received. The approach your using is wrong for what you need to achieve. – Rory McCrossan Mar 07 '19 at 09:33
  • Dude, XMLHTTPRequest does not change "window.location". `$("#ReportDiv").load("../pages/Report.html?userid=1", ` won't change the window.location value to "../pages/Report.html?userid=1`. So, please don't bother. I would rather expect help from someone who reads question for more than 1 second. – jitendragarg Mar 07 '19 at 09:33
  • @RoryMcCrossan Yes, I read the comment. XMLHTTPRequest does not go to server. Also, less than 10 seconds to mark a question duplicate. Tell me again, why shall we be talking right now? You don't have to answer every question, mate. – jitendragarg Mar 07 '19 at 09:53
  • 2
    I could have marked it too in less than 10 seconds. It is a very obvious question. If the Report.html is a php in disguise it can access the query parameters via the $_GET variables. If it is NOT, then the question is an X/Y problem. You have no need of the query parameters in Report.html, you can just save the parameters and then have the page that is loading Report.html do whatever is needed with those parms – mplungjan Mar 07 '19 at 09:54
  • Okay, that might work. I tried session storage btw. That doesn't work because the second page can't find the session details. Also, how is this duplicate of "use window.location". I did use window.location. I mentioned that in the question itself. It doesn't work with XMLHttpRequest, which people will know if they spend few seconds to understand the question. Don't you think? – jitendragarg Mar 07 '19 at 09:55
  • 1
    What second page? Report.html is not a second page. It is just some html that is rendered in the page when retrieved. There is no action possible in Report.html unless as I said it is actually a server generated page in which case the server generating code can access the GET array – mplungjan Mar 07 '19 at 09:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/189585/discussion-between-jitendragarg-and-mplungjan). – jitendragarg Mar 07 '19 at 09:56

0 Answers0