Skip to content

Instantly share code, notes, and snippets.

@IronGhost63
Last active February 28, 2020 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronGhost63/10c2071097518b7bf6e0929d8b61d264 to your computer and use it in GitHub Desktop.
Save IronGhost63/10c2071097518b7bf6e0929d8b61d264 to your computer and use it in GitHub Desktop.
upload.js
jQuery('.my-form').on('submit', (e) => {
e.preventDefault();
let form = e.target;
let formData = new FormData( form );
let userdata_access_token = getUserdataAccessToken();
// ถ้าต้องการเพิ่มข้อมูล ใช้ .append ได้เลย
formData.append('userdata_access_token', userdata_access_token);
// แล้วเอา formData ส่งไปเป็น data ของ $.ajax
jQuery.ajax({
url: "post-form.php",
type: "POST",
data: formData,
success: successCallback, // เขียน callback ตามปกติ
});
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment