1

We currently have a search page where hotels are listed dynamically via ajax calls.And per displayed hotel we have to display a tripadvisor widget. A sample tripadvisor widget code is as follows

<div id="TA_rated485" class="TA_rated">
<ul id="mdJZap41Mwg" class="TA_links shznH7pJf">
<li id="NnfwdIAYy" class="e9ZmnKZxo"><a href=http://www.tripadvisor.com/Hotel_Review-g190454-d228070-Reviews-Hotel_Royal-Vienna.html>Hotel Royal</a></li>
</ul>
</div>
<script src="http://www.jscache.com/wejs?wtype=rated&amp;uniq=485&amp;locationId=228070&amp;lang=en_US"></script>

The fun part is that the script tag links to a script which uses document.write. As this is after the page onload and called during an ajax call loop the document gets rewritten. Is there any work around in order to have the document.write not rewrite the page or a workaround for the widget where the widget is integrated in a different way other than the current document.write technique.

MilindaD
  • 7,533
  • 9
  • 43
  • 63
  • What does your AJAX response handler do? I take it you just grab whatever response HTML you get and insert it to the DOM? – chrisfrancis27 Aug 30 '12 at 12:10
  • The Ajax Response handler displays the hotel list. In this scenario the widget is inserted as well which includes a javascript link (look at the last line of the code in the question). However unfortunately the provided javascript code uses a document.write thus rewriting the whole page. – MilindaD Aug 30 '12 at 14:37

1 Answers1

0

This link may help you out with this issue

JavaScript Document.Write Replaces All Body Content When Using AJAX

or

you can go for jquery method

 $('slector').live(event,function(){
 //your code here
 });

This will bind your code to dynamically loaded element by Ajax.

Community
  • 1
  • 1
maximus ツ
  • 7,949
  • 3
  • 25
  • 54