I'm trying to use a select's onchange event to update the list of contacts in another select. My original code was
function companyUpdated(sel){
"use strict";
var id = sel.value;
$.post("index.php?r=clients/get-client-info&id="+id, function(data) {
$("#ClientInfo").html(data);
});
};
I then simply wanted to display a loading div at the beginning and hide it at the end by doing
function companyUpdated(sel){
"use strict";
var id = sel.value;
$("#loading").show();
$.post("index.php?r=clients/get-client-info&id="+id, function(data) {
$("#ClientInfo").html(data);
});
$("#loading").hide();
};
Now, the code updates the select properly, but I never see the Loading div.
I did all sorts of things and can prove the Loading div is in fact there and can be shown (as it is in other functions...), but not in this specific case.
Now when I swicth the function to use $.ajax, then the div appears correctly. So this is what I ended up with that works.
function companyUpdated(sel){
"use strict";
var id = sel.value;
$("#loading").show();
$.ajax({
async: false,
method: "POST",
url: "index.php?r=clients/get-client-info&id="+id,
timeout: 3000,
})
.done(
function(result){
$("#ClientInfo").html(result);
}
);
$("#loading").hide();
};
My question is why does $.ajax() display the Loading div and not $.post? Is this an expected behavior? I have a solution, but would like to actually understand.
Thank you for taking the time to help!