tags:

views:

154

answers:

4

Works fine just in FF:

    <script type="text/javascript">
    function loadContent(id,start) {
   $("#ContentRightBlockTest").load("cast_member.php?_type="+id+"&start="+start+"");   
}  
    </script>

whith onload in the body

<body onLoad="loadContent('cast',4);">
+4  A: 

Typically, you don't want to use the body onLoad with jQuery. jQuery provides a much better browser-independent way to run javascript when the document completely finishes loading. Try this:

    <script type="text/javascript">
    function loadContent(id,start) {
        $("#ContentRightBlockTest").load("cast_member.php?_type="+id+"&start="+start+"");   
   }
   $(loadContent('cast',4));
    </script>

Then remove your body onload. The $(--something here--); syntax will ensure the enclosed javascript gets run when the document loads.

Alternatively, you can try:

$(document).ready(function() { loadContent('cast',4); });
David Morton
Tkanks, make sense, but still dont't work in safari.
Mango
Can you be more specific? Is any code running in Safari? Do you have any Javascript errors in Safari?
David Morton
+1  A: 

Get rid of the onload event in the body and just slap this in the page

$(document).ready(function () {
    $("#ContentRightBlockTest").load("cast_member.php?_type="+id+"&start="+start+"")}
)
used2could
A: 

Is it possible that your HTML should read like this:

<body onload="loadContent('cast',4);">

with lower case attributes?

Dave Van den Eynde
A: 

I'm not sure what you mean by "don't work," so I'm going to go with just a few suggestions instead.

I'm not sure about Safari, but Internet Explorer will cache the results, causing a hiccup in your expectations. You can avoid this by appending a constantly-changing value onto the query-string.

function loadContent(id, start) {
  var t = new Date;
  $.get("cast_member.php", {'_type':id,'start':start,'t':t.getTime()}, function(result) {
    $("#ContentRightBlockTest").html(result);
  });
}

Additionally, it's advised to wait until the DOM has completely finished loading before firing off any requests. As such, jQuery code is best placed within the ready() event of the document. Below is a short-hand representation of this containing your function call.

$(function(){
  // Fire loadContent() once DOM is loaded
  loadContent('cast', 4);
});
Jonathan Sampson