Thursday, 15 March 2012

javascript - Chrome and Jquery strange behaviour -



javascript - Chrome and Jquery strange behaviour -

i had create simple jsp page displays 2 tables. there jsp page generates table, had phone call page different parameters , load result in different divs.

the first thing tried phone call 2 jquery loads:

$(function() { $("#res_05").load("tablegenerator.jsp", { "resource_name": "<%= resname1 %>", }, function(responsetext, textstatus, xmlhttprequest) { var firsttable = $("#res_05 table table").first(); $("#res_05").html(firsttable); $("<h1> resource <%= resname1 %> </h1>").insertbefore("#res_05 table"); }); $("#res_15").load("tablegenerator.jsp", { "resource_name":"<%= resname2 %>", }, function(responsetext, textstatus, xmlhttprequest) { var secondtable = $("#res_15 table table").first(); $("#res_15").html(secondtable); $("<h1> resource <%= resname2 %> </h1>").insertbefore("#res_15 table"); }); });

this simple page works in firefox , net eplorer 8, in chrome behaves in unusual manner: displays first table.

after first try, centralized loads in function before adding more complexity. script become this:

$(function() { loadtable("res_05", "<%= resname1 %>"); loadtable("res_15", "<%= resname2 %>"); }); function loadtable(divname, resname) { $("#" + divname).load("tablegenerator.jsp", { "resource_name": resname, }, function(responsetext, textstatus, xmlhttprequest) { var firsttable = $("#" + divname + " table table").first(); $("#" + divname).html(firsttable); $("<h1> resource " + resname + "</h1>").insertbefore("#" + divname + " table"); }); }

after alter page worked on browsers, chrome.

it seems can caused wrong javascript interpretation chrome, using jquery should rare case. after worked ie 8, didn't expect such behaviour in chrome.

i'm not expert in jquery, if isn't browser problem understand happens in such situations.

javascript jquery google-chrome cross-browser

No comments:

Post a Comment