$("document").ready(function(){
$("#btn").click(function(){
var title = $("#title").val();
var description = $("#description").val();
var texting = $("#texting").val();
$("#title").val('');
$("#description").val('');
$("#texting").val('');
$.ajax({
url: '../Model/AddPost.php',
type: 'POST',
data: {title:title, description:description, texting:texting},
success: function(data){
// alert(data);
}
});
$.ajax ({
type: "POST",
url: '../Model/AddPost.php',
data: {title:title, description:description, texting:texting},
success: function(data){
$("#textpost").html(data);
}
});
});
});
$("document").ready(function(){
$("#form").submit(function(e){
e.preventDefault();
var title = $("#title").val();
var description = $("#description").val();
var texting = $("#texting").val();
$("#title").val('');
$("#description").val('');
$("#texting").val('');
$.ajax ({
type: "POST",
url: '../Model/AddPost.php',
data: {title:title, description:description, texting:texting},
success: function(data){
$("#textpost").html(data);
}
});
});
});
<form method="post" class="auth-form">
<input type="text" name="login" placeholder="login" id="login">
<input type="password" name="password" placeholder="password" id="password">
<button id="submitBtn">Send</button>
</form>
const submitBtnElem = document.getElementById('submitBtn');
if(submitBtnElem) {
submitBtnElem.addEventListener('click', auth(e));
}
function auth(e) {
e.preventDefault();
const login = document.getElementById('login').value;
const password = document.getElementById('password').value;
const xhr = new XMLHttpRequest();
xhr.open("POST", "auth_request", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState != 4) return;
console.log( this.responseText );
}
xhr.send(`login=${login}&password=${password}`);
}