var form = document.querySelector('.exam_questions_form');
form.addEventListener('submit',function(ev){
ev.preventDefault();
var formData = new FormData(form);

var r = new XMLHttpRequest();
r.open(“POST”, “path/to/api”, true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
alert(“Success: ” + r.responseText);
};
r.send(formData);
return false;
});
In WordPress

add_action( 'wp_ajax_my_action', 'my_action_callback' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' );
function my_action_callback(){
echo 1;
die(0);
}

Admin URL in wordpress

<?php echo admin_url(‘admin-ajax.php’); ?>