Menu

Showing posts with label ajax. Show all posts
Showing posts with label ajax. Show all posts

Friday, November 29, 2013

[JS] วิธีการส่งไฟล์และข้อมูลจากฟอร์มโดยไม่ใช้การส่งค่าจากฟอร์ม
[JS] How to Send File with Form Data without Form Submission

jQuery และ Ajax ถูกใช้อัพโหลดไฟล์จากฟอร์ม HTML ไปยังเซิร์ฟเวอร์โดยไม่ใช้การส่งค่าจากฟอร์ม
jQuery and Ajax is used to upload file from HTML form to server without form submission

สมมติว่า ฟอร์ม HTML เป็นตามด้านล่าง
Assume that HTML form is below
<form id="form-id" action="upload.php" enctype="multipart/form-data" method="post">
     <table style="width: 100%;">
          <tbody>
               <tr>
                    <th><label for="id_path_program">Path program:</label></th>
                    <td><input id="id_path_program" name="path_program" type="file"></td>
               </tr>
               <tr>
                    <th><label for="id_description">Description:</label></th>
                    <td><input id="id_description" maxlength="250" name="description" type="text"></td>
               </tr>
          </tbody>
     </table>
     <input type="submit" value="Upload"/>
</form>