| Autor | Zpráva | ||
|---|---|---|---|
| sniclman Profil * |
#1 · Zasláno: 23. 6. 2014, 10:52:05
Ahoj,
můžete mi někdo poradit jak na upload obrázku přes ajax v IE8 a IE9? Firefox, chrome a IE11 zvládnou input.files a new FormData() (pokud jsem správně pochopil jedná se o API funkce?), nicméně IE8/9 tyto funkce nepodporují. Bohužel jsem na google nenašel žádné řešení, věšinou jen odkazy na složité funkce a nebo jQuery (s kterým neumím pracovat). Ukázka funkčního kódu (ne pro IE8/9): http://matraux.com/other/dynamic_img/ <div style="width: 100px; height: 100px; overflow: hidden; border: 2px #000000 solid; cursor: pointer;" onClick="dynamic_select(this);"> <img border="0" style="width: 100%; height: 100%;"> Click to upload <input type="file" name="image[]" style="display:none;"> </div> //ActiveXObject/XMLHttpRequest
function request(){return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();}
function dynamic_select(object){
var childs = object.childNodes;
for(i=0; i<=childs.length-1; i++){
if(childs[i].tagName == 'INPUT' && childs[i].type == 'file'){var file = childs[i];}
else if(childs[i].tagName == 'IMG'){var img = childs[i];}
else{}}
file.onchange=function(){dynamic_preview(this, img);};
file.click();}
function dynamic_preview(file, img){
//nefunguje
if(typeof(FormData) == "undefined"){
var formData = [];
formData.push('image', file);}
//nefunguje
else{
var formData = new FormData();
formData.append('image', file.files[0]);}
var httpRequest = request();
httpRequest.open("POST", '?', true);
httpRequest.onreadystatechange= function(){
if (httpRequest.readyState == 4){
if(httpRequest.status == 200){img.src=httpRequest.responseText;}
else{
if(httpRequest.status != 0){alert(httpRequest.status +":"+ httpRequest.statusText);}}}}
httpRequest.send(formData);} |
||
|
Časová prodleva: 12 let
|
|||
0