-1

I'm opening a new window to display a report using javascript and jquery in an MVC 4 application. The code is as follows.

window.open method:

    $(document).ready(function () {
        // validation stuff
            submitHandler: function (form) {
                var brewery = document.getElementById('BrewerySelect').value;
                var line = document.getElementById('LineSelect').value;
                var day = document.getElementById('datepicker').value;
                var width = window.innerWidth * 0.66;
                var height = width * window.innerHeight / window.innerWidth;
                var urlStr = '/DashboardReport/Report?brewery=' + brewery + '&line=' + line.trim() + '&day=' + day;
                alert(urlStr);
                window.open(urlStr, 'newwindow', 'width=' + width + ', height=' + height + ', top=' + ((window.innerHeight - height) / 2) + ', left=' + ((window.innerWidth - width) / 2));
            }
        });
    });

The controller does nothing, which I have tried as both PartialViewResult and ActionResult, the rest of the methods in the controller work fine for the ajax calls. The report works in a modal.:

    public ActionResult Report()
    {
        return View();
    }

The page that is opened:

@{
    Layout = null;
}
<html>
<head>
    <title>Report</title>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />

</head>
<body>
    <div id="reportBody" style="height: 100%;">

    </div>

    <script src="~/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="~/Scripts/scripts.js" type="text/javascript"></script>
    <script type="text/javascript">        
        $(document).ready(function () {
            var brewery = GetURLParameter('brewery');
            var line = GetURLParameter('line');
            var day = GetURLParameter('day');
            alert('document hit');
            SetReport(brewery, line, day);
        });

        function GetURLParameter(sParam)
        {
            var sPageURL = window.location.search.substring(1);
            var sURLVariables = sPageURL.split('&');
            for (var i = 0; i < sURLVariables.length; i++)
            {
                var sParameterName = sURLVariables[i].split('=');
                if (sParameterName[0] == sParam)
                {
                    return sParameterName[1];
                }
            }
        }​

        function SetReport(brewery, line, day) {
            var url = '@Url.Action("GetUrl")';
            alert('SetReport Hit ( action url = ' + url + ')');
            $.ajax({
                url: url,
                data: { breweryCode: brewery, packageLine: line, date: day },
                dataType: 'json',
                cache: false,
                type: "POST",
                success: function (data) {
                    alert('SetReport success. data = ' + data);
                    var url = '<iframe src="' + data + '" height="100%" width="100%" scrolling="auto"></iframe>';                           
                    $('#reportBody').html(url).show();                           
                },
                error: function (response) {
                    alert('document.ready() dashboardReportForm SetForm() method failed');
                }
            });
        }
    </script>
</body>
</html>

I've set alerts throughout the javascript to let me know what is getting hit, but none of the alerts are firing. The document.ready function is not being hit.

todd.pund
  • 689
  • 2
  • 11
  • 36

1 Answers1

1

There's a U+200b character after the ending bracket of GetURLParameter function, which causes syntax error. Remove it and it should work.

See No visible cause for "Unexpected token ILLEGAL"

Community
  • 1
  • 1
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
  • This was the ticket. It wasn't after the bracket, the problem WAS the bracket. Apparently, when I c/p that method for grabbing url parameters the font used was the issue. – todd.pund May 24 '16 at 17:37