Created
January 25, 2023 12:08
-
-
Save mudassaralichouhan/d280aeb7b38f1324d0d75040fbfea88a to your computer and use it in GitHub Desktop.
js issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const from = document.querySelector('form#group-send-message'); | |
from.onsubmit = (e) => { | |
e.preventDefault(); | |
const selectedGroup = document.querySelector('div[data-active]'); | |
if (! selectedGroup) { | |
swal('Please! first Select a group chat.', 'error'); | |
return; | |
} | |
if (! e.target.content.value) { | |
swal('Please! first some type message', 'error'); | |
return; | |
} | |
// const imageInput = from.querySelector('input[name="images[]"]'); | |
// const images = []; | |
// imageInput.files.forEach( (img, index) => { | |
// var reader = new FileReader(); | |
// reader.readAsDataURL(img); | |
// reader.onload = function () { | |
// images.push(reader.result); | |
// }; | |
// }); | |
const formData = new FormData(e.target); | |
formData.append('id', selectedGroup.getAttribute('data-id')); | |
$.ajax({ | |
url: "ajax/index.php?cmd=ecommerce/ajax/chat/group-send-message", | |
data: formData, | |
type: "POST", | |
cache: false, | |
contentType: false, | |
processData: false, | |
success: res => { | |
try { | |
res = JSON.parse(res); | |
} catch (e) { | |
if (res === '') { | |
swal('some thing was wrong', 'error'); | |
return; | |
} | |
document.querySelector('div#chat-box-body div').insertAdjacentHTML('beforebegin', res); | |
return; | |
} | |
if (res.status === false) { | |
swal(res.message, 'error'); | |
} | |
}, | |
error: res => {}, | |
}); | |
} | |
from.querySelector('label').onclick = (e) => { | |
from.querySelector('input[name="images[]"]').click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment