首页 \ 问答 \ ExtJS解码方法无法解码“文件上传后”(ExtJS decode method fails to decode “"” After File Upload)

ExtJS解码方法无法解码“文件上传后”(ExtJS decode method fails to decode “"” After File Upload)

我将JSON格式结果发送回持有$ quot符号的客户端。 由于某种未知原因,代码中断了。

以下是来自ext-all-debug的代码:

doDecode = function(json){
   return eval("(" + json + ")");    FAILS HERE
},

这是我的JSON,因为它离开了服务器(据我所知,我希望服务器没有花时间解码它的空闲时间。):

{
success: true,
total: 1,
results: [{
    "ID": -1,
    "Value": "POChangeRequestlblCustomerCatalogNumber",
    "Description": "",
    "Labels": {
        "1": {
            "ID": -1,
            "LanguageID": 1,
            "Value": "Catalog Number",
            "ToolTip": "",
            "LanguageName": "English",
            "KeyID": -1,
            "KeyValue": "POChangeRequestlblCustomerCatalogNumber",
            "KeyDescription": ""
        },
        "2": {
            "ID": -1,
            "LanguageID": 2,
            "Value": "&quot;", <<< THIS IS THE BAD PART!!!
            "ToolTip": "",
            "LanguageName": "Hebrew",
            "KeyID": -1,
            "KeyValue": "POChangeRequestlblCustomerCatalogNumber",
            "KeyDescription": ""
        }
    },
    "ServerComments": "1"
}]
}

此JSON以text / html内容类型发送,因为它是文件上载操作的结果。 这可能是问题的一部分吗?

好的,我继续追查问题,发现ExtJS对隐藏的iframe返回的值执行此功能:

doFormUpload : function(o, ps, url){
        ...

            try{
                doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;
                if(doc){
                    if(doc.body){
                        if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ 
                            r.responseText = firstChild.value;
                        }else{
                            r.responseText = doc.body.innerHTML;  << THIS IS WHERE MY &quot; get decoded back to " (sign)
                        }
                    }

                    r.responseXML = doc.XMLDocument || doc;
                }
            }
            catch(e) {}

            ...
    }

这个问题是否有一个很好的解决方法。 似乎浏览器自动解码值???? 任何人???? 这是一个重大问题!!


I have a JSON format result sent back to the client that hold the $quot sign. for some unknown reason the code breaks.

Here is the code that bricks from ext-all-debug:

doDecode = function(json){
   return eval("(" + json + ")");    FAILS HERE
},

Here is my JSON as it left the server (As far as I know , I hope the server doesn't take the time to decode this &quot on its free time.):

{
success: true,
total: 1,
results: [{
    "ID": -1,
    "Value": "POChangeRequestlblCustomerCatalogNumber",
    "Description": "",
    "Labels": {
        "1": {
            "ID": -1,
            "LanguageID": 1,
            "Value": "Catalog Number",
            "ToolTip": "",
            "LanguageName": "English",
            "KeyID": -1,
            "KeyValue": "POChangeRequestlblCustomerCatalogNumber",
            "KeyDescription": ""
        },
        "2": {
            "ID": -1,
            "LanguageID": 2,
            "Value": "&quot;", <<< THIS IS THE BAD PART!!!
            "ToolTip": "",
            "LanguageName": "Hebrew",
            "KeyID": -1,
            "KeyValue": "POChangeRequestlblCustomerCatalogNumber",
            "KeyDescription": ""
        }
    },
    "ServerComments": "1"
}]
}

this JSON is sent in a text/html content type as it is the result of a file upload operation. could that be part of the problem?

Ok, I have continued to trace down the problem and found that ExtJS does this function on the returned value from a hidden iframe:

doFormUpload : function(o, ps, url){
        ...

            try{
                doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;
                if(doc){
                    if(doc.body){
                        if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ 
                            r.responseText = firstChild.value;
                        }else{
                            r.responseText = doc.body.innerHTML;  << THIS IS WHERE MY &quot; get decoded back to " (sign)
                        }
                    }

                    r.responseXML = doc.XMLDocument || doc;
                }
            }
            catch(e) {}

            ...
    }

Is there a good workaround for this issue. it seems that the browser automatically decodes the value???? any one???? this is a major issue !!


原文:https://stackoverflow.com/questions/8989639
更新时间:2023-09-19 15:09

最满意答案

我不确定Featherlight库是如何工作的,但它可能与HTML ID有关。 您可以只使用一次ID,但是为foreach中的每个图像复制id“mylightbox”。

尝试将foreach更改为以下内容:

foreach($page->children as $childIndex => $child) {
  if ($child->head_image) {
    $image = $child->head_image;  
    echo "<li class='item'><a href='#' data-featherlight='#mylightbox" . $childIndex . "'><img id='mylightbox" . $childIndex . "' src='{$image->url}' class='image'></a><p class='worktitle'>$child->title</p></li>"; 
  }
}  

I am not sure how exactly Featherlight library works, but it is probably connected with HTML IDs. You can have each id used only once, but you duplicate id "mylightbox" for every image in foreach.

Try to change the foreach to something like this:

foreach($page->children as $childIndex => $child) {
  if ($child->head_image) {
    $image = $child->head_image;  
    echo "<li class='item'><a href='#' data-featherlight='#mylightbox" . $childIndex . "'><img id='mylightbox" . $childIndex . "' src='{$image->url}' class='image'></a><p class='worktitle'>$child->title</p></li>"; 
  }
}  

相关问答

更多