下载停止在jquery-1.9.1.min.js中工作?

时间:2018-04-06 06:45:49

标签: javascript jquery jquery-ui asp.net-web-api

我的javascript文件中有一个函数用于下载带注释的画布,然后将其移动到服务器。其余的jquery工作正常..但由于某些原因,这些特定的函数已停止工作。

     $("#ContentPlaceHolder1_btnNext").click(function () {
        var canvas = paper.project.activeLayer.view.element;
        var img = $(canvas).parent().find('img')[0];

        //  var name = $("#ContentPlaceHolder1_Label9").text();
        var name = $("#ContentPlaceHolder1_HiddenField1").val();

        var mergeCanvas = $('<canvas>')
        .attr({
            width: $(img).width(),
            height: $(img).height()
        });

        var mergedContext = mergeCanvas[0].getContext('2d');
        mergedContext.clearRect(0, 0, $(img).width(), $(img).height());
        mergedContext.drawImage(img, 0, 0);

        mergedContext.drawImage(canvas, 0, 0);
        //alert(canvas);

        self.downloadCanvas(mergeCanvas[0], name);
        //alert(mergeCanvas[0]);
        //alert(name);
    });

    this.downloadCanvas = function (canvas, filename) {

        /// create an "off-screen" anchor tag
        var lnk = document.createElement('a'), e;

        /// the key here is to set the download attribute of the a tag
        lnk.download = filename;


        /// convert canvas content to data-uri for link. When download
        /// attribute is set the content pointed to by link will be
        /// pushed as "download" in HTML5 capable browsers

        lnk.href = canvas.toDataURL();

        if (filename != "") {
            /// create a "fake" click-event to trigger the download
            if (document.createEvent) {

                e = document.createEvent("MouseEvents");
                e.initMouseEvent("click", true, true, window,
                                 0, 0, 0, 0, 0, false, false, false,
                                 false, 0, null);

                lnk.dispatchEvent(e);

                // save image to server 

                $.ajax({
                    type: 'POST',
                    url: 'home.aspx/MoveImages',
                    data: '{ "imageData" : "' + filename + '" }',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (msg) {
                        //alert("Done, Picture Uploaded.");
                    }
                });

它在一个月前完美运作..但它已停止工作,我无法弄清楚可能会有什么变化?

使用以下脚本:

<script type="text/javascript" src="https://code.jquery.com/jquery- 
 1.8.2.min.js"></script>

<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>

webmethod:

[System.Web.Services.WebMethod(EnableSession = true)]
    public static void MoveImages(string imageData)
    {
        string fileName = "";
        // get computer name

        string clientMachineName;
        clientMachineName = Dns.GetHostName();
        string computerName = clientMachineName.Split('-').First();

        // get download location

        string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        string sourcePath = Path.Combine(pathUser, "Downloads");







        string pathstring = @"D:\........";


        string class = HttpContext.Current.Session["class"].ToString().Trim();
        string sub = HttpContext.Current.Session["subject"].ToString().Trim();
        string targetPath = System.IO.Path.Combine(pathstring, class);
        string pathstring1 = targetPath;
        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
        string destFile = System.IO.Path.Combine(pathstring1, sub);





        // Use Path class to manipulate file and directory paths.



        if (System.IO.Directory.Exists(sourcePath))
        {

            string[] jpg = System.IO.Directory.GetFiles(sourcePath, "*.jpg");
            string[] png = System.IO.Directory.GetFiles(sourcePath, "*.png");
            string[] files = jpg.Concat(png).ToArray();

            // Copy the files and overwrite destination files if they already exist.
            foreach (string s in files)
            {
                // Use static Path methods to extract only the file name from the path.
                if (s.Length > 0)
                {
                    fileName = System.IO.Path.GetFileName(s);
                    sourceFile = Path.Combine(sourcePath, fileName);
                    //destFile = System.IO.Path.Combine(targetPath, fileName);
                    destFile = System.IO.Path.Combine(destFile, fileName);
                    if (File.Exists(destFile))
                    {
                        File.Delete(sourceFile);

                    }
                    else
                    {
                        System.IO.File.Move(s, destFile);
                    }
                }
            }

        }

    }

Background.js:

'use strict';

let disableShelf = () => chrome.downloads.setShelfEnabled(false);
chrome.runtime.onInstalled.addListener(disableShelf);
chrome.runtime.onStartup.addListener

(disableShelf);

0 个答案:

没有答案