2011-11-21 31 views
0

這裏是一個簡單的AJAX的例子提交表單:jQuery的Ajax表單上傳

$('#submit').click(function() { 
    var myName = $('#name').val(); 
    var myContent = $('#content').val(); 

    // ajax 
    $.ajax({ 
     type: 'post', 
     url: '/ajax.process.php', 
     data: { 
      post_name: myName, 
      post_content: myContent 
     }, 
     dataType: 'json', 
     success: function (data) { 
      if (data.status.OK == 'OK') { 
       console.log('OK'); 
       return false; 
      } else { 
       console.log('ERROR'); 
       return false; 
      } 
     } 
    }); // end ajax 
}); 

這是我的html:

<form method='post' enctype='multipart/form-data' action='ajax.process.php' id='form-main'> 
    <textarea cols='50' rows='5' id='content' name='post_content'></textarea> 
     <input type='text' id='name' class=' name='post_name'> 
     <input type='file' id='attach' name='attach'/> 
      <input type='button' value='Submit' id='express-form-submit'> 
    </form> 

只是想知道爲什麼所有的形式完美的作品除了連接,我的服務器端腳本永遠不會收到$ _FILES。

任何想法?

+1

可能重複? http://stackoverflow.com/q/166221/508702 –

回答

1

由於無法訪問其內容,因此無法由jquery發佈這些文件。另外,你不會發布表單,你使用jQuery做了一個單獨的ajax請求。

+0

你能更具體一點嗎? :d – greenbandit