Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery show loading in <select>

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?

like image 792
user2209644 Avatar asked Jan 29 '14 15:01

user2209644


People also ask

How to show loading symbol in jQuery?

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.

How to show spinner on button click in jQuery?

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.

How to use load function in jQuery?

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).


1 Answers

Use this code instead

modelSelect.html("<option> loading ... </option>");

Hope it helps.

like image 57
php-dev Avatar answered Sep 22 '22 09:09

php-dev