Jquery 在Ajax成功调用中更改Iframe src-Web服务器将获得两次源引用
我有一个带有iframe元素的html页面,当我通过ajax调用获取一些信息后试图设置iframe源代码时,它将从服务器获得多个对源代码引用的get请求 Iframe.html:Jquery 在Ajax成功调用中更改Iframe src-Web服务器将获得两次源引用,jquery,ajax,iframe,Jquery,Ajax,Iframe,我有一个带有iframe元素的html页面,当我通过ajax调用获取一些信息后试图设置iframe源代码时,它将从服务器获得多个对源代码引用的get请求 Iframe.html: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <script src="jquery-2.1.4.min.js"></script> &
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script src="jquery-2.1.4.min.js"></script>
<script src="bigfile.js"></script> // 3MB Size
</head>
<body>
<iframe id="samplefile"></iframe>
<script type="text/javascript">
$.ajax({
type: "Get",
url: my_url,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$("#samplefile").attr("src", "data.html");
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="jquery-2.1.4.min.js"></script>
</head>
<body>
Some Content
</body>
</html>
//3MB大小
$.ajax({
键入:“获取”,
url:my_url,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据){
$(“#samplefile”).attr(“src”、“data.html”);
}
});
data.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script src="jquery-2.1.4.min.js"></script>
<script src="bigfile.js"></script> // 3MB Size
</head>
<body>
<iframe id="samplefile"></iframe>
<script type="text/javascript">
$.ajax({
type: "Get",
url: my_url,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$("#samplefile").attr("src", "data.html");
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="jquery-2.1.4.min.js"></script>
</head>
<body>
Some Content
</body>
</html>
一些内容
屏幕截图:
正如您看到的屏幕截图所示,有两个jquery脚本Get request from data.html。如何避免这些不必要的服务器Get请求