🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.javascript
Article #51510

Object formdata

#51510
From: Jakub
Date: Mon, 27 Apr 2015 13:03
47 lines
1884 bytes
Witam

Mam taki kod w html:

<div id="aimg">
    <img src="plki.jpg">
    <img src="pik02.jpg">
    <img src="pik03.jpg">
    <img src="pik04.jpg">
</div>


<script>
//pobranie w js kolekcji typu img
var aimg = document.getElementById("aimg");
var ilosc = aimg.getElementsByTagName("img");

//jak skonwertować kolekcję typu img na formData?
//jak za pomocą js sformatować objekt typu formData aby przygotować 
formularz typu "post" do wysłania.

var fData = new FormData();

fData.append('photos[]', file, file.name);   ???
  fData.append('photos[]', arsc, file.id);   ??


// Set up the request.
var xhr = new XMLHttpRequest();

// Open the connection.
xhr.open('POST', 'jakisplik.html', true);

// Set up a handler for when the request finishes.
xhr.onload = function () {
    if (xhr.status === 200) {
     // File(s) uploaded.
//     s = xhr.responseText
   }
};

// Send the Data.
xhr.send(fData);

</script>

Jakub 
Technical Details
Message-ID: <553e337c$0$2208$65785112@news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
From: "Jakub" <jak74@interia.pl>
Newsgroups: pl.comp.lang.javascript
Subject: Object formdata
Date: Mon, 27 Apr 2015 15:03:56 +0200
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 16.4.3528.331
X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331
Lines: 48
Message-ID: <553e337c$0$2208$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 31.61.140.132
X-Trace: 1430139772 unt-rea-a-01.news.neostrada.pl 2208 31.61.140.132:10205
X-Complaints-To: abuse@news.neostrada.pl
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit