-1

I am sending http request to my server and the response is a html:

<html>
<head>
  <link rel = "stylesheet" type="text/css" href="CSS/jQUERYUI.css">
</head>
<body>
<div id = "first">
data : someData
</div>
</body>
</html>

I want the current page will refresh with the response data so I tried:

$http({
  method: 'POST',
  url: '/someUrl'
}).then(function(response) {
      var win = window.open(window.location.href, '_blank');
      $(win.document.body).html(response.data)
  }, function(error) {

  });

And some of the 535 ways to reload page using js 535-ways-to-reload. Still I was not able to reload the current page with the response html.

Also I want the the url of the current page won't change. angularjs ways to do so will be great as well.

Thanks for ant help.

Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114

3 Answers3

2

why don't you route it to /someUrl in a main div inside body?

Koushik Chatterjee
  • 4,106
  • 3
  • 18
  • 32
1

You're almost there. When you receive the html from the server, you rewrite the document with it. But do not redirect to itself, otherwise the browser rewrites once again.

$http({
  method: 'POST',
  url: '/someUrl'
}).then(function(response) {
      $(win.document.body).html(response.data)
  }, function(error) {

  });
AlainD
  • 6,187
  • 3
  • 17
  • 31
0

You don't need to refresh the page, just override the HTML of the current page with JavaScript:

window.document.body.parentNode.innerHTML = response.data;

As your result has HTML tags already, you might want to strip those first:

response.data.replace(/<?\/html>/, '');
dejakob
  • 2,062
  • 14
  • 21