Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. $(".Ulozit_upraveny_produkt").click(function() {
  2. event.preventDefault();
  3. var pridat_id = $(this).attr('data-produkt-id');
  4.  
  5. var form_product = $("#productEdit").serializeArray();
  6. var files = document.getElementById("file_upload").files;
  7. var formData = new FormData();
  8.  
  9. form_product.forEach(function(item) {
  10. formData.append(item.name, item.value);
  11. });
  12.  
  13.  
  14. for (var i = 0; i < files.length; i++) {
  15. var file = files[i];
  16.  
  17.  
  18. // Add the file to the request.
  19. formData.append('image[]', file, file.name);
  20. }
  21. var xhr = new XMLHttpRequest();
  22. xhr.open('POST', './library/editProdukty.php', true);
  23. xhr.onload = function() {
  24. if (xhr.status === 200) {
  25. // File(s) uploaded.
  26. //uploadButton.innerHTML = 'Upload';
  27. } else {
  28. alert('Stala se chyba!');
  29. }
  30. };
  31.  
  32. xhr.send(formData);
  33. xhr.onreadystatechange = function()
  34. {
  35. if (xhr.readyState == 4 && xhr.status == 200)
  36. {
  37. console.log(xhr.responseText);
  38. }
  39. }
  40.  
  41.  
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement