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:

  1. disable sync ajax (it block ui until response ends , don't need achieve loading indication),
  2. begin showing loading (in modal window or div highest z-index (modal if force user waiting),
  3. on ajax complete event hide loading
  4. on ajax success (and maybe failure) act needed

http://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -