enctype = “multipart/form-data” works different between ie9 and chrome
我想将某些数据以enctype等于multipart / form-data的形式发布到另一个域,因为我希望在服务器端保留未修改的数据。
这是我的测试代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <textarea name="txt" rows="20" cols="80"> </textarea> function x_domain_post(url, data) { var dd = document.createElement('div'); var ifrname ="client_proxy"; dd.innerHTML ="<iframe id='" + ifrname +"' name='" + ifrname +"' width=0 height=0 ></iframe>"; document.getElementsByTagName('body')[0].appendChild(dd); var ifr = document.getElementById(ifrname); var f = document.createElement('form'); f.action = url; f.method ="post"; f.enctype ="multipart/form-data"; f.target = ifr.name; f.innerHTML = f.innerHTML +"<textarea name='request'>default</textarea>"; document.getElementsByTagName("body")[0].appendChild(f); document.getElementsByName("request")[0].value=data; f.submit() setTimeout(function(){document.getElementsByTagName("body")[0].removeChild(f);}, 1000); } <button onclick="x_domain_post('http://192.168.232.128/add', document.getElementsByName('txt')[0].value)"> |
chrome中的请求是:
1 2 3 4 5 6 7 8 9 10 11 12 | ... Content-Type:multipart/form-data; boundary=----WebKitFormBoundary9zCD31eJSHkdb8ul ... ------WebKitFormBoundary9zCD31eJSHkdb8ul Content-Disposition: form-data; name="request" a b o ------WebKitFormBoundary9zCD31eJSHkdb8ul-- |
但是在IE9中:
1 2 3 4 5 | POST /add HTTP/1.1 ... Content-Type: application/x-www-form-urlencoded ... request=a%0D%0A%0D%0Ab%0D%0A%0D%0Ao |
您的任何帮助将不胜感激!
这有帮助吗?
http://www.bennadel.com/blog/1273-Setting-Form-EncType-Dynamically-To-Multipart-Form-Data-In-IE-Internet-Explorer-.htm
Apparently in IE, you have to set the
"encoding" of the form rather than the
"enctype". The good news is, you can
set both values without concern and
this will take care of the problem