私はjavascript&jquery-backendを書いており、iframeファイルアップロードの標準的なajaxミームを使用しています。
eval()
サーバーから返された文字列にjavascript を使用する必要があります(はい、わかっています)。文字列は次のようになります (常にそうとは限らないため、eval が必要です)。
$("#uploaderCinfo").html("<h1>file(s) received</h1>");
サーバー、firebug、フィドラーは、それがまさにそれが送信するもの(およびhttpヘッダー)であることを教えてくれます:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 54
$("#uploaderCinfo").html("<h1>file(s) received</h1>");
ただし、iframeから得られるのは次のとおりです。
<pre>$("#uploaderCinfo").html("<h1>file(s) received</h1>");</pre>
が追加されたのには正当な理由があると思います.<pre>'s
を使用してそれらを削除できますslice()
. しかし、html-string 内のエスケープはどこから来るのでしょうか?
< が何らかの形でエスケープされているため、この方法<h1>file(s) received</h1>
はそのままページに追加されます。エスケープを防ぐことはできますか、それとも javascript-means を使用して元に戻す必要がありますか?
助けてくれてありがとう。
参考までに: 以下の最小限の使用可能なソース: (注: シングルクォートは、セッションが生成される Smalltalk にエスケープされます)
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;