AJAX browser update with script tags in response

I'm having trouble calling jQuery AJAX. My code works fine when I request a page without javascript, but when I have script tags in my code, everything starts to get weird.

It seems that any script tags that link to external URLs are causing browser redirection. In firefox, the page does not fill. In Safari, the page clears and loads the contents of the AJAX response. In both browsers, the URL does not change.

Specifically about my problem; I have a tab control in which I am trying to embed a walkscore widget. Since it is quite heavy on the client side, I want to download it only after the user clicks on the tab. The AJAX walkscore page is as follows:

<script type="text/javascript">
  var ws_address = "1 Market St, San Francisco";
  var ws_width = "500";
</script>
<script type="text/javascript" src="http://www.walkscore.com/tile/show-tile.php?wsid=MY_WSID">
</script>

script, AJAX? ?

- -

. . :

: index.html walkscore.html

index.html

function widget() {
  var widget = $('#walkscore');
  $.get('/walkscore.html', function(data) {
    $('#loading').slideUp(function() {
      widget.html(data);
      loaded[name] = true;
      widget.slideDown();
    });
  });
}

walkscore.html -

index.html , . , , js. , js. , js, document.write. , $.getScript, index.html

- -

, , document.write. javascript walkscore document.write jquery.html , , . () js noob. document.write? , script ?

+3
6

- document.write. , :

document.write() , , ( script ) . , write - , , , - , . , . . . ()

, , , document.write div. script , document.write . :

http://www.webxpertz.net/forums/showthread.php?threadid=11658

, - !

+1

script html, $.getScript().

+1

document.write .. Firefox, :

<script type="text/javascript">

  // save default document.write function so we can set it back
  var write_func_holder = document.write;

  // redefine document.write to output text target div
  document.write = function(text) {
    $('#ad_container').html($('#ad_container').html() + text);
  }
</script>

<script language="JavaScript" type="text/javascript" src="javascriptfile">
</script>

<script type="text/javascript">
  // reset document.write function
 document.write = write_func_holder;
</script>

Safari, document.write IE6, IE7 . Firefox .

, - , , , , IE6/7 Safari.

+1

document.write - . , , writeCapture.js .

+1

script, , - .

0

, , , . , jquery, , - , .

, , - - .

jquery, div $.ajax(), . , , tweet retweet, . javascript.

<script type="text/javascript" src="http://www.retweet.com/static/retweets.js"></script>

, , script ajax, jquery , html $.ajax().

script :

if(!url)
{
 var url=window.location.href;
}
if(!size)
var size="big";
var height="75";
var width="54"
if(size=="small")
{
  height="22";
  width="120";
}
if(!username)  
  var username="none";
url=url.replace("?", "*");
var src="http://www.retweet.com/widget/button/"+size+"/"+username+"/"+url;
document.write('<iframe src="'+src+'" height="'+height+'" width="'+width+'" frameborder="0" scrolling="no"></iframe>');

document.write.

, , .

0

Source: https://habr.com/ru/post/1709738/


All Articles