2

I have an MVC4 project, and an error that happens usually after the second time of 'SetInterval'. The first time the opening window is fine, but after it I receive an error on this line :

$(w.document.body).html(data.toString());

the error is:

JavaScript runtime error: Permission denied

Here is the code:

<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>

UPDATE: A Data controller

        // 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;
    }
David
  • 239
  • 1
  • 2
  • 12
  • The opened page might still be loading when you try to set it's html already. Think of window.open as an async function. Also have a look at http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript#comment-32382848 On eof the answers talks about window.open inside ajax call succes handlers. – Shilly Sep 01 '16 at 09:17

0 Answers0