Jump to content

Hom35tead

New Members
  • Posts

    3
  • Joined

  • Last visited

Hom35tead's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry, i completely left that out. It is "uncaught Type (in promise) error. Pretty much all it says.
  2. Ok so here is the deal. If I packege all this code up into a single flat file in html. It works or at least says successful and does not throw an error. Whether the actual file moves or not I dont yet. However as soon as I break it down into Form on PHP file, Javascript in a js file referenced from PHP. It stops working and gives me an error. "Uncaught type (in promise)" The whole reason I am trying to avoid the EventListener is because if the user opens the overlay (which kicks off the function) and then closes it without uploading a file. When they reopen that form it listens for the 'submit' event two times. Uploads two files and console logs them separately, so I know it is running the actual function 2 times. I like the onlick or onsubmit binding (false binding) as I can reuse this function over and over without it screwing up my other stuff. Like I can use the same function on multiple parts of the application without havng to have a listener on every page. Is there a better approach? -Home3s
  3. Ok So i just wanted to remove the event listener from my uploadFiles() function in my js. Because I want the function to kick off only when I click that button and not any other button in the form as well ass preventing the listener from running twice if somebody closes the overlay and goes back into it without refreshing. Here is my code. Why do I keep receiving a promise error. It is pretty vanilla stuff. Something I am just not seeing.The code that worls with the eventListener. ` /* ----- Upload File / Image -----*/ function uploadFile(uid) { const url = 'process.php'; const form = document.querySelector('form'); //let uid = document.getElementById('upid').value; var data = { auploadid: "1", auserid: "1", }; const btn = document.getElementById('newFiles'); //console.log("Run Onlick"); form.addEventListener('submit', e => { //console.log("Run Heard The Click"); e.preventDefault(); const files = document.querySelector('[type=file]').files; const formData = new FormData(); for (let i = 0; i < files.length; i++) { let file = files[i]; //console.log(uid); formData.append('files[]', file); formData.append('uploadid', uid); } fetch(url, { method: 'POST', body: formData }).then(response => { return response.text(); }).then(data => { console.log(data); }); }); return; } And this is the code that throws the error. Again, all I am trying to do is remove the event Listener. /* ----- Upload File / Image Without Listener-----*/ function uploadFiles(uid) { const url = 'process.php'; //const form = document.querySelector('form'); const form = document.getElementById("uploadForm"); //e.preventDefault(); const files = document.querySelector('[type=file]').files; const formData = new FormData(); for (let i = 0; i < files.length; i++) { let file = files[i]; //console.log(uid); formData.append('files[]', file); } formData.append('uploadid', uid); fetch(url, { method: 'POST', body: formData }).then(response => { return response.text(); }).then(data => { console.log(data); }); return; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.