jquery - Is this a threading issue? -


i'm using cherrypy 5.0.1 server-side framework.

the following code performs searches on local disk's files. searches strings fed front-end's ajax calls.

import cherrypy import os import os.path import json   def searchforfiles(search_path, base_filename):     directory = os.path.abspath(search_path)     files = []     f in os.listdir(directory):         if os.path.isfile(f):             files.append(f)     hit = []     f in files:         if fnmatch.fnmatch(f, '*' + base_filename + '*'):             hit.append(f)     hit = json.dumps(hit)     return hit    class gui_db_interface:      # whatever codes here......      @cherrypy.expose     def searchforfiles(self, search_path, base_filename):         return searchforfiles(search_path, base_filename) 

the front-end code:

  var searchsimilarfiles = function(event, filename_base) {     var $uls = $('div#overview_box ul.existing_files');     var current_input = $('input#primary_input').val();     $.each($uls, function(index, ul) {       var path_name = $(ul).siblings('div.folder_info')         .find('div.path_name').data("path");       $.post('searchforfiles', {         'search_path': path_name,         'base_filename': current_input       }, function(databack) {         var lis = json.parse(databack);         $(ul).empty();         console.log(lis);         (l in lis) {           $(ul).append("<li>" + lis[l] + "</li>");         }       });     });   }; 

my code has following problems:

  1. there 4 different divs containing 4 different search_path information using $.each() function make ajax call backend service. on click event there supposed 4 different calls, first div works.
  2. actually calls made 4 divs $.each(), , service on back-end can found successfully, returning status code 200, first div gets right result, the other 3 empty array.
  3. logging on back-end shows problem in end. 'files' variable first call returns right array, while other 3 return empty arrays.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -