2016-02-09 74 views
1

我有一個表單,我試圖通過ajax發送值。但我收到以下錯誤:Uncaught TypeError:從ajax發送數據時發生非法調用錯誤

Uncaught TypeError: Illegal invocation

我被卡住了,找不到我在哪裏錯了。有什麼建議嗎?

阿賈克斯

<html> 
<head> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" </script> 
<script type="text/javascript"> 
$(document).ready(function() { 
$("#submit_custom").click(function() { 
e.preventDefault(); 
var postData = new FormData(); 
    postData.append('file[]', $('input[type=file]')[0].files[0]); // after this line 
    postData.append('trxid', $('input[name=trxid]')); 
    postData.append('orderid', $('input[name=orderid]')); 
    postData.append('custid', $('input[name=custid]')); 
    if(proceed) 

$.post('upload.php', post_data, function(response){ 
if(response.type == 'error'){ //load json data from server and output message 
    output = '<div class="error">'+response.text+'</div>'; 
    }else{ 
    output = '<div class="success">'+response.text+'</div>'; 
    $("#upload_form").slideUp(); //hide form after success 
        } 
    $("#upload_form").hide().html(output).slideDown(); 
    }, 'json'); 
    }); 
    }); 
    }); 
    </script> 
</head> 
<body> 
<h2>Hello <?php echo $user ?> </h2> <p> "You have successfully done purchasing process.</p> 
<div id="upload_form"> 
<p>To send your size details for your order please upload the following file:</p> 
<p>Download custom size form Provide us your custom size: <a href="download.php?download_file=custom-measurement-form.pdf">File.pdf</a></p> 
<form enctype="multipart/form-data" action="" method="post"> 
    <input type="text" name="trxid" value="<?=$trx?>"> 
    <input type="text" name="orderid" value="<?=$orderid?>"> 
    <input type="text" name="custid" value="<?=$customerid?>"> 
    <input type="file" name="file"> 
    <input type="submit" id="submit_custom"> 
</form> 
</div> 
</body> 
</html> 
+0

什麼是'post_data'? – dandavis

回答

0

你得到非法調用因爲jQuery無法序列的postData對象$.post。我想你需要添加.val()

postData.append('file[]', $('input[type=file]')[0].files[0].val()); // after this line 
postData.append('trxid', $('input[name=trxid]').val()); 
postData.append('orderid', $('input[name=orderid]').val()); 
postData.append('custid', $('input[name=custid]').val()); 
相關問題