iframe文件上载或jquery正在转义我的字符串

iframe文件上载或jquery正在转义我的字符串,jquery,iframe,escaping,Jquery,Iframe,Escaping,我正在编写一个javascript&jquery后端,并使用iframe文件上传的标准ajax meme 我们需要对服务器返回的字符串使用javascripteval()(是的,我知道)。 <pre>$("#uploaderCinfo").html("&lt;h1&gt;file(s) received&lt;/h1&gt;");</pre> 字符串可以是这样的(但并不总是如此,我们确实需要eval): 这是服务器端转义。你的后端是什么?

我正在编写一个javascript&jquery后端,并使用iframe文件上传的标准ajax meme

我们需要对服务器返回的字符串使用javascript
eval()
(是的,我知道)。
<pre>$("#uploaderCinfo").html("&lt;h1&gt;file(s) received&lt;/h1&gt;");</pre>
字符串可以是这样的(但并不总是如此,我们确实需要eval):


这是服务器端转义。你的后端是什么?

我认为这确实不是逃避它的服务器,而是你的浏览器。它添加了
,因为它的内容是文本/普通的(比如已经建议使用@Pinal)

我使用FF对吗?(编辑:我刚在这里找到错误报告:)

从iframe检索内容时,请尝试使用
.textContent
而不是innerHTML


还要看看哪个建议使用
var text=x.innerText | | x.textContent
实现浏览器兼容性

这很可能是从服务器端本身逃逸出来的。你在使用什么服务器端技术?@techfoobar我自己编写服务器端,只使用套接字(在Squeak Smalltalk中)。我不认为是服务器做的;在答案中添加了完整的HTTP响应。萤火虫也告诉我。你为什么不把它夹在纸条之间呢tag@rajeshkakawat“收到的文件”只是一个例子。一般来说,服务器会根据需要生成许多不同的JS响应。我自己只使用普通套接字(在Squeak Smalltalk中)编写后端,Firebug和Fiddler都告诉我服务器不是逃避它的服务器。我认为内容类型是错误的
内容类型:text/plain
。尝试text/htmlIf如果我这样做,那么
iframeContents
将成为不完整的
ploaderCinfo”).html(“文件接收内容类型:text/javascript?
text/javascript
也与我的原始文件相同
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 54

$("#uploaderCinfo").html("<h1>file(s) received</h1>");
<pre>$("#uploaderCinfo").html("&lt;h1&gt;file(s) received&lt;/h1&gt;");</pre>
self plain: '<div id="uploadform',uUpload,'">
    <form id="theuploadform',uUpload,'" method="post" action="">
        <input id="userfile',uUpload,'" name="userfile',uUpload,'" 
            size="10" type="file" multiple />
        <input id="formsubmit',uUpload,'" type="submit" value="upload" 
            onClick="', INSIDE THE ONCLICK (see below) ,'" />
    </form>
<span id="anim',uUpload,'">
</span>
<div id="iframe',uUpload,'" style="width: 0px; height: 0px; display: none;">

INSIDE THE ONCLICK:

$("#anim',uUpload,'").html("<img src=''/files/public/loading.gif'' />");
var iframe = $(''<iframe name="postiframe',uUpload,'" 
        id="postiframe',uUpload,'" style="display: none" />'');
    $("body").append(iframe);
    var form = $("#theuploadform',uUpload,'");
    form.attr("action", "/uploadAjax?session=',
        (session at: #zId),'&upload=',uUpload,'");
    form.attr("method", "post");
    form.attr("target", "postiframe',uUpload,'");
    form.attr("enctype", "multipart/form-data");
    form.attr("file", $("#userfile',uUpload,'").val());
    form.submit();
    $("#postiframe',uUpload,'").load(function () {
        iframeContents = 
            $("#postiframe',uUpload,'")[0].contentWindow.document
                                                    .body.innerHTML;
        $("#anim',uUpload,'").html(""); /*removes animation*/
    console.log("A");
    console.log(iframeContents);
    console.log("B");
    iframeContents = iframeContents.slice(5, iframeContents.length-6);
    console.log(iframeContents);
    console.log("C");
    eval(iframeContents);
    console.log("D");
    });
    return false;