天天看点

Ajax 异步获取的js内容成功后,无法在success中执行其js内容?

1、因为Ajax 异步获取的js内容是作为字符串赋值给变量,在success中未执行。

2、解决方式:将获取的js内容赋值到页面上,再执行js方法。

js页面:

<script type="text/javascript">

function he(str){

  $i=str;

  alert($i);

}

</script>

ajax页面:

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>

<script type="text/javascript" charset="utf-8">

$.ajax({

url: "test.html",

cache: false,

success: function(html){

  $("#content").html(html);

  he("hechunhau");

}

});

</script>