2013-05-02 20 views
5

Bir PHP betiğine AJAX aracılığıyla veri göndermek için FormData kullanmaya çalışıyorum. Girdi tipi metin değerleriyle ilgili herhangi bir sorun görünmüyor, ancak dosya eklemeyi denediğimde hata alıyorum TypeError: Value, formData arabirimini uygulamıyor.Javascript: TypeError: Değer arabirimi uygulamıyor FormData

FormData'da yeniyim, ancak web'de aradım ve bu hatayla ilgili herhangi bir doküman bulamadım. Burada

var formData = new FormData();  
formData.append('photos', $('#emp_photos').files[0]); 

var i kundakçı olsun hata: Burada JavaScript'S

<form id="item_form" class="item_form" enctype="multipart/form-data"> 
    <div class=""> 
     <label for="emp_photos">photos</label> 
     <input id="emp_photos" class="inputText" type="file" value="" name="emp_photos"> 
    </div> 
</form> 

: Burada

form

TypeError: Value does not implement interface FormData. 

...igger("ajaxComplete",[N,p]),--b.active||b.event.trigger("ajaxStop")))}return N},... 

jquery....min.js (line 5) 

ben yanlış burada ne işim var?

DÜZENLEME: ajax parçası

$.ajax({ 
    type: 'POST', 
    url: '"; 
    echo $_SESSION["url_base"]; 
    echo "operations/add_employes', 
    data: formData, 
    xhr: function() { // custom xhr 
     myXhr = $.ajaxSettings.xhr(); 
     if(myXhr.upload) { // check if upload property exists 
     myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload 
     } 
     return myXhr; 
    }, 
    success: function(msg) {/*...*/} 

}); 
+1

nerede ajax çağrıdır. Bunu görebilir miyiz? – KingKongFrog

+0

Bu uygun bir çözüm gibi görünüyor http://stackoverflow.com/questions/15259632/upload-image-as-base64-with-jquery-ajax –

+0

Ty Tim bana bunu çözmeme yardımcı oldu :) –

cevap

2
var inputs = $("input[type=file]"), 
    files = []; 

// jquery or javascript have a slightly different notation 
// it's either accessing functions() or arrays [] depending on which object you're holding at the moment 
for (var i = 0; i < inputs.length; i++){ 
    files.push(inputs.eq(i).prop("files")[0]); 
    //files.push(inputs[i].files[0]); 
    //filename = inputs[i].files[0].name; 
    //filesize = inputs[i].files[0].size; 
} 

if (formdata) { 
    // you can use the array notation of your input's `name` attribute here 
    formdata.append("emp_photos[]", files); 
} 
+0

thnx çok, harika – bhawin

+0

"emp_photos []" php arka ucunda nasıl olacak? – bhawin

+0

$ _POST ['emp_photos'] foreach ($ _POST ['emp_photos'] $ i => $ değer olarak) { echo "emp_photos [$ i]" $ değer
"; } –

İlgili konular