在JS调用中传递了错误的数据

时间:2012-01-06 20:32:22

标签: ajax model-view-controller

我有一种奇怪的情况。我正在努力扩展一些第三方代码,这是通过编写我们自己的提供程序然后配置系统来使用我们的代码而不是代码附带的基本提供程序来完成的。我让提供程序工作得很好但是当我从JS块中调用它时,在JS调用中传递GUID。 GUID和Response参数都回来了 WAY 搞砸了!

要点的主要内容是:

    ASCX文件中的
  1. function addImage(fileName, fileSize, fileType, guid, response)
  2. addImage('unk', 'unk', 'unk', '<%: myGuid %>', '<%: fullPath %>');也在ASCX文件中
  3. 我在下面的代码中添加了注释(// ************* HERE **** HERE **** HERE ************* //

    我们的AJAXImageUploader.ascx代码:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<RainWorx.FrameWorx.DTO.Media.Media>>" %>
    
                <!--<form enctype="multipart/form-data" method="post">-->
    
                <%:Html.GlobalResource("UploadImages")%> (<%:Html.GlobalResource("MaxImagesInformational", SiteClient.Settings["MaxImagesPerItem"]) %>) - <%:Html.GlobalResource("ImageFees",
                                                    Html.SiteCurrency(AccountingClient.GetAllFeeProperties().Where(fp => fp.Processor.Equals("RainWorx.FrameWorx.Providers.Fee.Standard.ImageCount") &&
                                                    fp.Event.Name.Equals((string)ViewData["Event"]) &&
                                                    fp.ListingType.Name.Equals((string)ViewData["ListingType"]) &&
                                                    fp.Name.Equals("FirstImage")).Single().Amount),
                                                    Html.SiteCurrency(AccountingClient.GetAllFeeProperties().Where(fp => fp.Processor.Equals("RainWorx.FrameWorx.Providers.Fee.Standard.ImageCount") &&
                                                    fp.Event.Name.Equals((string)ViewData["Event"]) &&
                                                    fp.ListingType.Name.Equals((string)ViewData["ListingType"]) &&
                                                    fp.Name.Equals("AdditionalImages")).Single().Amount)
                                                    )%>
    
                                                    <input type="file" id="photo" name="photo" />
    
                <!--</form>     -->
    
                <script type="text/javascript">
                    // ************* HERE **** HERE **** HERE ************* //
                    // ************* HERE **** HERE **** HERE ************* //
                    function addImage(fileName, fileSize, fileType, guid, response) {                    
                        var thumbnails = $("div#sortablethumbnails");
    
                        var newSpan = $("<span class='imagecontainer'/>").appendTo(thumbnails);
    
                        var newImg = $("<img/>").appendTo(newSpan).attr("src", guid + response);
    
                        $("<input type='hidden' name='media_guid_" + guid + "'/>").appendTo(newSpan).attr("value", guid);                    
                        $("<input type='hidden' name='media_ordr_" + guid + "'/>").appendTo(newSpan).attr("class", "order");
                        $("<a href='#' class='deleteimage'><img src='Content/images/General/Delete.png' alt='<%:Html.GlobalResource("RemoveImage") %>' style='margin-left: -30px;' /></a>").appendTo(newSpan);
    
                        RefreshOrder();
                    }
    
    
                    $(document).ready(function() {
                        $("#photo").makeAsyncUploader({
                            upload_url: $.url('Listing/AsyncUpload'),
                            flash_url: 'Content/swf/swfupload.swf',
                            button_image_url: 'Content/images/blankButton.png',
                            disableDuringUpload: 'INPUT[type="submit"]',
                            button_text: '<%:Html.GlobalResource("ChooseImages") %>'
                        });
    
                        $("div#sortablethumbnails").html($("input#ThumbnailRendererState").val());
                    });
    
                </script>  
    
                <script type="text/javascript">
                    $(document).ready(function() {
                        $("div#sortablethumbnails").sortable({
                            opacity: 0.7,
                            revert: false,
                            scroll: true,
                            tolerance: 'pointer',
                            update: function(event, ui) {
                                RefreshOrder();
                            }
                        });
                        $("div#sortablethumbnails").disableSelection();
    
                        $("a.deleteimage").live("click", function() {
                            $(this).parent().remove();
                            RefreshOrder();
                            return false;
                        });
    
                        <% if (Model != null) 
                        { 
                            //var imageList = Model.Where(a => a.Context == "UploadListingImage").ToList();
                            var imageList = Model.Where(m => m.Type.Equals("D4I.Providers.MediaLoader.DateHashedURI_AWS")).ToList();
                            if(imageList.Count > 0)
                            {
                                //Get Workflow
                                Dictionary<string, string> workflowParams = CommonClient.GetAttributeData("MediaAsset.Workflow", "UploadListingImage");
                                //Load Media
                                IMediaLoader mediaLoader = RainWorx.FrameWorx.Unity.UnityResolver.Get<IMediaLoader>(workflowParams["Loader"]);
                                Dictionary<string, string> loaderProviderSettings = CommonClient.GetAttributeData(mediaLoader.TypeName, "UploadListingImage");
    
                                foreach (Media media in imageList)
                                {
                                    string fullPath = mediaLoader.Load(loaderProviderSettings, media, "ThumbCrop");
                                    string myGuid = media.GUID.ToString();
                                    %>
                                    // ************* HERE **** HERE **** HERE ************* //
                                    // ************* HERE **** HERE **** HERE ************* //
                                    addImage('unk', 'unk', 'unk', '<%: myGuid %>', '<%: fullPath %>');
                                    <%
                                }
                            }
    
                        } %>
                    });
    
    //                function AddImage(src) {
    //                    $("div#sortablethumbnails").append("<span class='imagecontainer'><img src='" + src + "' /><span class='order'></span><a href='#' class='deleteimage'>Delete</a></span>");
    //                    RefreshOrder();
    //                }
    
                    function RefreshOrder() {
                        var images = $(".imagecontainer");
                        for (var x = 0; x < images.length; x++) {
                            $(".imagecontainer .order:eq(" + x + ")").val(x);
                        }
                    }                                                                                
    
                </script>      
    
    <%--            <input type=button id=debuginfo value="Debug Info" />--%>
    
                <div id=sortablethumbnails></div>
    } 
    %>
    

    结果:

    <span class="imagecontainer">
      <img src="http://s3.amazonaws.com/deal4it/dev/ListingImage/20120106/096b341f-2e7c-4ef1-b969-37a62a877e67_thumbcrop.jpg">
      <input type="hidden" name="media_guid_http://s3.amazonaws.com/deal4it/dev/" value="http://s3.amazonaws.com/deal4it/dev/">
      <input type="hidden" name="media_ordr_http://s3.amazonaws.com/deal4it/dev/" class="order" value="2">
      <a href="#" class="deleteimage">
        <img src="Content/images/General/Delete.png" alt="Remove Image" style="margin-left: -30px;">
      </a>
    </span>
    

    我们的装载机看起来像:

    namespace D4I.Providers.MediaLoader
    {
        public class DateHashedURI_AWS : RainWorx.FrameWorx.Providers.MediaLoader.IMediaLoader
        {
            public string Load(Dictionary<string, string> providerSettings, Media media, string variationName)
            {
                Variation variation = media.Variations[variationName];
    
                string path = String.Format("{0:yyyy}{0:MM}{0:dd}", variation.Asset.DateStamp);
                if (providerSettings.Count < 6)
                    providerSettings = DefaultProviderSettings;
    
                return Amazon.GetMediaUrl(path: path
                                        , fileName: variation.Asset.Reference
                                        , providerSettings: providerSettings
                                        , context: media.Context);
            }
    
            public Dictionary<string, string> DefaultProviderSettings
            {
                get
                {
                    Dictionary<string, string> retVal = new Dictionary<string, string>();
                    // deleted values are our AWS login info //
                    return retVal;
                }
            }
    
            public bool VerifyProviderSettings(Dictionary<string, string> providerSettings)
            {
                return (DefaultProviderSettings.Keys.Except(providerSettings.Keys).Count() <= 0);
            }
    
            public string TypeName
            {
                get { return "D4I.Providers.MediaLoader.DateHashedURI_AWS"; }
            }
        }
    }
    

    调用返回值的方式如下:

    public static string GetMediaUrl(string path, string fileName, string context, Dictionary<string, string> providerSettings = null)
    {
        // Initialize the AWS API...
        _providerSettings = providerSettings;
        Initialize();
    
        string absoluteURL = String.Format("{0}/{1}/{2}/{3}/{4}/{5}", BaseURL, BucketName, RootFolder.StripSlashes(), context.FixContext(), path, fileName);
        Uri uri = new Uri(absoluteURL);
        return uri.AbsoluteUri;
    }
    

    我可以逐步完成每一段代码并看到它正常工作除了 AJAXImageUploader.ascx中的代码。我甚至尝试在ASCX中的JS块中找到C#代码,我可以在它上面打破它,但我仍然无法实现它。在所有其他情况下,我可以确认media.GUID实际上是一个有效的GUID,并且Load()函数返回AWS上图像的有效URI字符串。

    任何想法如何跟踪这个?

1 个答案:

答案 0 :(得分:0)

发现源公司编写的SWF包含对JS文件的调用,该文件在成功上载后对数据块进行进一步更改。我从RainWorx获得了我需要的数据并且瞧 - 它们都开始正常工作了。我喜欢缺乏关于这些隐藏宝石的可行文档! &LT;抱怨/&gt;