2012-03-27 98 views
1

具有使用jQuery阿賈克斯 我要上傳使用ajax.But碼的follwing行的文件從server.M越來越resposnse問題M的工作不 第1頁:響應的錯誤

<script language="javascript" src="jquery-1.7.1.js"/></script> 
<script language="javascript" src="jquery.form.js"/></script> 
<script language="javascript"> 
$(document).ready(function(){ 
    $('#photoimg').change(function(){ 
    var fd=new FormData(); 
    $.ajax({ 
     type:'POST', 
     url:'NewuploadScript.php', 
     data:fd, 
     contentType: 'application/x-www-form-urlencoded', 
     async:true, 
     cache:false, 
     processData: true, 
     success:function Result(data2) { 
     document.write(data2); 
     } 
    }); 
    }); 
}); 
</script> 
<form> 
<input type="file" id="photoimg" name="file" multiple> 
<input type="submit" id="BtnSbmt" value="Upload"/> 
</form> 

PAG2:

<?php 
echo $name= basename($_FILES['photoimg']['name']); 
echo $size= basename($_FILES['photoimg']['size']); 
?> 

當我運行代碼的jquery顯示以下錯誤:

Uncaught TypeError: Illegal invocation 
jQuery.extend.param.addjquery-1.7.1.js:7601 
buildParamsjquery-1.7.1.js:7658 
jQuery.extend.paramjquery-1.7.1.js:7621 
jQuery.extend.ajaxjquery-1.7.1.js:7467 
(anonymous function)ImageUploader.php:18 
jQuery.event.dispatchjquery-1.7.1.js:3256 
jQuery.event.add.elemData.handle.eventHandlejquery-1.7.1.js:2875 
+0

請訪問http:// stackoverflow.com/questions/9048358/illegal-invocation-error-in-ajax-jquery-1-7-1 – dotoree 2012-03-27 10:25:09

+0

@dotoree它的否工作.... – kishor 2012-03-27 10:34:59

+0

你得到它的工作.. http://stackoverflow.com/questions/5140156/illegal-operation-on-wrappednative-prototype-object – 2012-11-20 11:47:57

回答

0

很難分辨出錯誤消息意味着什麼,而不會看到Ajax交換中返回的內容。您的PHP代碼不應該讀取

echo $var_name = ... 

因爲這是一項任務。請嘗試以下...

<?php 
    echo basename($_FILES['photoimg']['name']); 
    echo basename($_FILES['photoimg']['size']); 
?> 

或者只是

print_r($_FILES); 
+0

後把代碼它將顯示陣列() – kishor 2012-03-27 10:43:28

0

對於初學者編輯:

success:function (data2) { 
     document.write(data2); 
     } 

也許問題與FORMDATA相關看到this

+0

米沒有得到它 – kishor 2012-03-27 10:44:57

+0

@kishor功能需要匿名,刪除'結果' – dotoree 2012-03-27 10:57:24

+0

好點,但錯誤之前。我試圖運行代碼,並在「甚至提交之前」得到「WrappedNative原型對象的非法操作」。我認爲Kishor需要從jquery.form插件站點複製和粘貼示例代碼。 – Pete 2012-03-27 11:16:00