I am using AJAX for making a custom plugin in WordPress. I have successful made some pages. But whatever I do, AJAX doesn’t even make a call in a particular page. I have checked the console, no request is made and syntax is valid.
My code:
function onSubmit(token) {
document.getElementById("result").innerHTML += "<p style="color: green;">Processing.........</p>";
var form = document.forms["dt_login_form"];
var formData = new FormData(form);
$.ajax({
url: "/login/",
method: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
enctype: 'multipart/form-data',
processData: false,
success: function (data) {
if(data.status == 'success'){
document.getElementById("result").innerHTML = "<p style="color: green;">Successfully Logged In! Redirecting.....</p>";
} else if(data.status == 'fail'){
$('form').addClass('ahashakeheartache');
$('form').on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e){
$('form').delay(200).removeClass('ahashakeheartache');
});
document.getElementById("result").innerHTML = "<p style='color: red; float:center; text-align: center; font-size: 20px; '>Request Failed with Error:<br>" + data.message + "</p><br>";
}
},
error: function (err) {
console.log(err);
document.getElementById("result").innerHTML = "<p style='color: red;'>Request Failed with some Fatal Errors. Contact System Administrator or check Console for more details. </p><br><br>";
}
});
}
I have tried removing other parameters, still it isn’t working. Whereas in other page, almost same code, it works.