3

使用 Uploadify 和 JGrowl 组合:

<link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/jgrowl.css" />
<script type="text/javascript" src="js/jquery1.4.4.js"></script>
<script type="text/javascript" src="js/jgrowl.js"></script>
<link rel="stylesheet" type="text/css" href="css/artworkDesigner.css" />  
<link href="js/uploadify-2.1.4/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/uploadify-2.1.4/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/uploadify-2.1.4/swfobject.js"></script>
<script type="text/javascript" src="js/uploadify-2.1.4/jquery.uploadify.v2.1.4.min.js">/script>

<script type="text/javascript">    
    // <![CDATA[    
    var uploadType = "art";    
    var templateID = "42scs";

    $(document).ready(function() {

        $('#fileInput').uploadify({

            'uploader': 'js/uploadify-2.1.4/uploadify.swf',    
            'script': 'js/uploadify-2.1.4/UploadHandler.ashx',    
            'cancelImg': 'js/uploadify-2.1.4/cancel.png',    
            'scriptData': { 'type': uploadType, 'templateID': templateID },    
            'auto': true,    
            'multi': true,    
            'fileDesc': 'Image Files',    
            'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',    
            'queueSizeLimit': 90,    
            'sizeLimit': 4000000,    
            'buttonText': 'Choose Images',    
            'folder': '/uploads/test',    
            'onComplete': function(event, ID, fileObj, response, data) {

                if (response != "1") {

                    alert(response);   // ALERTS 'ERROR TEXT' which is expected

                    // DOESNT RUN THIS LINE:, AND REST OF SCRIPT SEEMS TO FREEZE 
                    $.jGrowl("<strong>Error!</strong><br />" + response, { sticky: true });
                    alert("flag"); // THIS IS NOT RUNNING

                } else {

                    alert(fileObj.name + "\n" + fileObj.filePath + "\n" + ID + "\n");
                    alert(response);

                }

            }

        });

    });

    // ]]></script>

此脚本工作正常,当 templateID 设置为实数时(末尾没有字符串以故意抛出错误),但是当42scs如上面的代码所示传入无效字符串时,脚本会发出警报

“一些错误文本”

当服务器端抛出异常时,哪个是正确的返回值。然后脚本停止做任何其他事情,当它打算抛出 Jgrowl 错误时。任何想法为什么这没有发生?

我在另一个页面上使用完全相同的 Jgrowl,它工作正常。

4

1 回答 1

3

对 Jquery 库的双重引用会发生冲突:

<script type="text/javascript" src="js/jquery1.4.4.js"></script>
<script type="text/javascript" src="js/uploadify-2.1.4/jquery-1.4.2.min.js"></script>
于 2011-02-01T14:18:38.050 回答