I'm using jQuery 3.3.1.
Reading through the page on .ajax() I was a bit confused on some things.
Currently I'm using code like this. I stripped out some code to make it more readable.
$.ajax({
method: "POST",
dataType: "json",
url: "includes/contactAjax.php",
data: { action: "getCompanyContacts", companyid:
$('#project_company').val() },
success: function (data) {
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus + ' - ' + errorThrown);
}
});
So I have the .ajax and then success function and error function within the ajax call.
Then I saw this note while reading.
Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
So one of my questions is, is the success function in my ajax call the same as the jqXHR.success() and the error function the same as the jqXHR.error?
Or are they two different things?
If they are different is it better to use the internal success or the jqXHR.done?
I've seem to be using that in my code too, maybe got it from a different example I looked at.
I removed some code to make it more readable.
$.ajax({
method: "POST",
url: "includes/projectAjax.php",
data: { action: "saveWrkNote", projectid: projectId, userid: userId }
})
.done(function( msg ) {
$('#frmWrkNote').modal('hide');
getWorkNotes();
});
I hope I'm making sense.
Both code blocks work just fine with 3.3.1. I just want to make sure for one I'm consistent across my program.
I'm also having an intermittent error on the second code block so I need to add some error code to see if it is having the problem or something else.
I plan on rewriting them to the best way and to be consistent.
Thanks,
Jeffery