What I'm trying to do should be simple.
I am trying to send some form values to an mvc controller that returns JSON.
If I return to success, I will show one popup if I get false. I will show another popup.
But in the console, I get two errors:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user experience. For more help, check http://xhr.spec.whatwg.org/.
browserLink:37 Setting 'XMLHttpRequest.withCredentials' for synchronous requests is deprecated.
Navigated to http://aso.local/
and the page just reloads.
Here is my code:
$('#mail-message-btn').click(function () {
if ($("form")[0].checkValidity()) {
var formParams = $('#contact-form').serialize();
$.post('/umbraco/surface/Contact/ContactForm', formParams, function (data) {
processData(data);
});
}
});
function processData(data) {
$('#mail-failure').hide();
$('#invalid-email').hide();
$('#empty-field').hide();
$('#mail-success').hide();
if (data.success == 'True') {
$('#mail-message-header').toggleClass('mail-message-error', false);
$('#mail-message-header').toggleClass('mail-message-success', true);
$('#mail-success').show();
$('#mail-message').show();
alert("true");
} else if (data.success == 'False') {
alert("false");
$('#mail-message-header').toggleClass('mail-message-error', true);
$('#mail-message-header').toggleClass('mail-message-success', false);
$('#mail-failure').show();
$('#mail-message').show();
}
}
I set the test warning windows to make sure that I got to the right, if blocks, and when I do this, it works! (popups show), but as soon as I click ok in the warning window, my popup disappears!
So disappointing, I also tried $ .Ajax with the same result!
reference
source