我有一个MVC4项目,并且通常在'SetInterval'的第二次之后发生错误。第一次打开窗口很好,但之后我在这一行收到错误:
$(w.document.body)的.html(data.toString());
错误是:
JavaScript运行时错误:权限被拒绝
以下是代码:
<html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<title>Home</title>
<script type="text/javascript">
alert('1');
$(document).ready(setInterval(function () {
$.ajax({
url: '/api/data/',
data: { pcName: '' },
type: 'GET',
success: function (CLID) {
//
if (CLID != null) {
$.ajax({
data: { line: CLID },
type: 'POST',
datatype: 'html',
url: '/Home/PopPage/',
success: function (data) {
var w = window.open("about:blank", 'PopPage', 'height=300,width=200');
$(w.document.body).html(data.toString());
}
});
}
}
});
}, 2000));
</script>
</head>
<body style=" height: 200px;width: 700px;">
<div>
</div>
</body>
</html>
更新:数据控制器
// GET api/data/5
public string Get(string pcName)
{
string Line="";
SetLogFiles();
Logger.Write("Data");
List<Campaign> CampaignList = new List<Campaign>();
Logger.Write("Before PcName");
// do db logic
try
{
pcName = System.Environment.MachineName;
Logger.Write("PC Name: "+pcName);
Line = DBAccess.GetDataLinesByKey(pcName);
}
catch (Exception ex)
{
Logger.WriteError(ex);
}
return Line;
}