Skip to content

Instantly share code, notes, and snippets.

@mudassaralichouhan
Created January 25, 2023 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudassaralichouhan/d280aeb7b38f1324d0d75040fbfea88a to your computer and use it in GitHub Desktop.
Save mudassaralichouhan/d280aeb7b38f1324d0d75040fbfea88a to your computer and use it in GitHub Desktop.
js issues
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