A页面:
<script>
$.ajax({
url : b.html
});
</script>
b.html页面
<script>
functon test(){
alert(1)
}
</script>
请问在ajax加载成功,如何才能执行B页面的 test()函数 ?并可以传参
A页面:
<script>
$.ajax({
url : b.html
});
</script>
b.html页面
<script>
functon test(){
alert(1)
}
</script>
请问在ajax加载成功,如何才能执行B页面的 test()函数 ?并可以传参
如果b页面只有script,直接命名为js文件,script标签引入即可。否则涉及到跨域了,用jsonp。
$.ajax({
url : 'http://fanyi.baidu.com/',
type: 'get',
dataType: 'jsonp',
jsonp: "callback",
jsonpCallback: "receive",
success: function(data) {
console.log(data)
}
});
function receive(data) {
console.log(data);
}
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
JSONP