javascript - How to write jQuery-AJAX function to append the list items received from PHP and show the "Loading..." message until he response is recieved? -
i'm having 1 select control on form. want populate select control list values comes php file in form of ajax response. how should , how should show 'loading...' message until response received php file?
<label class="col-sm-4 col-sm-offset-1 control-label">select store<span style="color:#ff0000">*</span> :</label> <input type="hidden" name="module_url" id="module_url" value="http://localhost/modules/stores/stores.php">
the necessary php code snippet follows :
switch( $op ) { case "get_all_stores": // available stores. $ret_store = $objstore->getallstorebypage(''); if(!$ret) { $error_msg = $objstore->getallerrors(); $data = array(); $data['error_message'] = $error_msg; $data = json_encode($data); echo $data; die; } else { $data = array(); $data = $objstore->getresponse(); echo json_encode($data); die; } break; }
the jquery-ajax code tried follows :
$(document).ready(function() { var module_url = $('#module_url').val(); $.ajax({ url : module_url, cache: false, datatype: "json", type: "get", async: false, data: { 'request_type':'ajax', 'op':'get_all_stores' }, success: function(result, success) { //what write here in order append data items select control , show 'loading...' message until response received } else { //what write put error messages } } }); });
ok, seems best way this:
- disable sync ajax (it block ui until response ends , don't need achieve loading indication),
- begin showing loading (in modal window or div highest z-index (modal if force user waiting),
- on ajax complete event hide loading
- on ajax success (and maybe failure) act needed
Comments
Post a Comment