Using JavaScript to upload a file without using a form | JavaScript and Ajax Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 9

  • @HDITrae
    @HDITrae ปีที่แล้ว

    Great tutorial, thank you. I suggest revising the title to: "How to upload a file with Ajax without using a form"

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว +1

      Sometime we write titles optimized for search engines rather than humans. But you're right.

  • @claudeandre-v5m
    @claudeandre-v5m ปีที่แล้ว

    Simple to follow, the best tutorial I was able to find for my need (thanks) - I have a question regarding the example: How do I capture the ".then((data) =>" to a text string? Searched for a very long time but could not find a working solution.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Hey, we capture the server's response (data) as a string using the response.text() method. If the server returns JSON data, we use the response.json() method to parse the data as JSON.

  • @tiagoborges5108
    @tiagoborges5108 ปีที่แล้ว

    Great video but i have some issues concerning the filereader object that i can not understand when we are doing a file upload.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Thanks. Do you mean the Formdata object?

    • @tiagoborges5108
      @tiagoborges5108 ปีที่แล้ว

      No the filereader if you want to preview the files you are updating.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Hey, the filereader object has nothing to do with the file upload action.
      We are calling the filereader object to read the file (image) and display it in the page.
      This action runs when we selecting a file with the choose file button.
      The upload action runs when we press the upload button.
      I have modified the code from this tutorial and added a preview with the filereader.
      Check it out:
      digitalfox-tutorials.com/youtube-files/Tiago.zip
      Tell me if it works.

    • @tiagoborges5108
      @tiagoborges5108 ปีที่แล้ว +1

      @@DigitalFox-tutorials Thank you very much for the explanation and the code, i already try it to better understand.