Refreshing a table

i have this form


Im trying to submit the form using fetch()

poc_form.addEventListener('submit', e => {
	e.preventDefault();
	const data = new URLSearchParams();
	for(const p of new FormData(poc_form)) {
		data.append(p[0], p[1], p[2], p[3]);
	}
	fetch('add_poc_engine.php', {
		method: 'POST',
		body: data
	}).then(response => response.text()).then(response => {
		document.querySelector('.poc_msg').innerHTML = response;
	}).catch(error => console.log(error));
	
	update_poc();
});
function update_poc(){
	const xhttp = new XMLHttpRequest();
	xhttp.onload = function(){
		document.querySelector("#poc_table").innerHTML = this.responseText;
	}
	xhttp.open("GET","updated_poc_table.php");
	xhttp.send();
}

the result is


Is it ok that im using the fetch() to post and add to the table and ajax to refresh the table, or s there a better way?

You could use the fetch response to return the updated table.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.