i have a jquery function that retrieves data from a php file and puts all that into a select list, which works just fine, the problem is that it takes some time to load and i wanted to show a loading text in the select while its loading, however it doesn't seem to work, here's what i've tried:
var modelSelect = $('[name="model"]'); // this is the select <select> list
$('[name="make"]').on('change', function(){ // another <select> that fires up the ajax
var chosen = $(this).val();
$.ajax({
type: "POST",
url: "process.php",
data: {'send': chosen},
beforeSend: function(){
modelSelect.html("loading"); //doesn't work
},
success: function(data){
modelSelect.html(data);
}
});
});
any ideas how i can make it say loading there?
You can just use the jQuery's . ajax function and use its option beforeSend and define some function in which you can show something like a loader div and on success option you can hide that loader div.
Answer: Use the ajaxStart() and ajaxStop() Method While working with Ajax, showing a loading spinner or displaying a message with some animation like "Loading... Please Wait" is popular way to indicate the user that Ajax request is in progress.
The jQuery load() method is a simple, but powerful AJAX method. The load() method loads data from a server and puts the returned data into the selected element. Syntax: $(selector).
Use this code instead
modelSelect.html("<option> loading ... </option>");
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With