0

I am trying to refresh just a part of my website (the left part in which a list with topics appear), but it don't work for me. I get a very weird screen on that left part if I click the refresh button. The script I am using is this:

$(function() {
   $("#refresh").click(function(evt) {
      $(".bgleft").load("left.php")
      evt.preventDefault();
   })
})

The weird screen I am getting is a white blank screen with a random text on it (that does not exist). I don't understand why it is happening. For a live example: go to (edited out) and click on "refresh" at the left frame.

Edit:

The HTML snippet: <body class="bgleft">

1BJK903
  • 167
  • 1
  • 2
  • 11

4 Answers4

1

In left.php there are two lines of code which are showing theese characters.

for(var n = 1; n < 7; n++)
document.write(String.fromCharCode(Math.round(Math.random()*25)+97));

Try to remove them, it should help.

Also as sad in other answers send only contents of <body> in response because scripts are already included in the site.

Juris Vaiders
  • 635
  • 8
  • 22
1

It's generally not a good idea to send a complete HTML page when doing a partial update. If you look at what's produced by your left.php, it's the complete page (with <html> tags and everything) you use in your iframe.

Either create a page that only renders the body of the left.php and use that for partial update. Or look here for how to refresh an iframe.

PS: Framesets are hopelessly deprecated and really limiting in terms of design, dynamic/javascript functionality and future extensibility. Consider not using them...

Community
  • 1
  • 1
pap
  • 27,064
  • 6
  • 41
  • 46
  • I know that it isn't a very good idea, but for this kind of site it is better to use, I guessed. This is the html snippet by the way: – 1BJK903 Sep 28 '12 at 08:52
  • It's almost never "better" to use framesets. It's a deprecated technology (removed in HTML5), the DOM and javascript support is not consistent across browsers making them messy to work with. Scrollbar behavior is also inconsistent across browsers, making it difficult to create cross-browser compatible design plus a whole lot of other issues. But it's your site and you'll do it your way ;) – pap Sep 28 '12 at 08:57
0

How come you are loading the same page HTML, HEAD, BODY inside the current BODY tag?

$(function() {
    $("#refresh").click(function(evt) {
        evt.preventDefault();         
        $(window.top.window).find('frame[name=left]').reload();
    })
})
Ghassan Elias
  • 2,213
  • 1
  • 14
  • 17
0

You should be only fetching the content to be updated, not the whole page. Currently, the whole page is being fetched including html, body and even script tags. The jQuery and other scripts are also being loaded again because of this. This can cause major problems later.

Vishal
  • 2,030
  • 22
  • 27
  • How can I fetch the content only? The script is in left.php which is only the left frame for as I know... – 1BJK903 Sep 28 '12 at 08:54