从使用Ajax发出请求的函数中获取文本

时间:2016-10-05 18:20:02

标签: javascript php jquery ajax html5

$.ajax({
      url: 'db_employer_info_lookup.php',
      type: 'POST',
      dataType: 'json'

  }).done(function(data) {
        // console.log(data.employee_info[0].length);
        for (var i = 0; i < data.employee_info[0].length; i++) {
          if(i%2 == 0){
            $('#the-team-wrapper .flex-content').append('<div class="employee-profile-pic flex-item" data-img-src="'
            +data.employee_info[0][i]['profile_pic']+'"></div><div class="employee-bio-wrapper flex-item"><h2>'
            +data.employee_info[0][i]['firstname']+" "+data.employee_info[0][i]['lastname']+'</h2>'+$('<h3 />')
            .html(get_job_title(data.employee_info[0][i]['id']))+'<p>'+data.employee_info[0][i]['bio']+
            '</p></div>');
          }else {
            $('#the-team-wrapper .flex-content').append('<div class="employee-bio-wrapper flex-item"><h2>'
            +data.employee_info[0][i]['firstname']+" "+data.employee_info[0][i]['lastname']+'</h2>'+**$('<h3 />')
            .html(get_job_title(data.employee_info[0][i]['id']))**+'<p>'+data.employee_info[0][i]['bio']
            +'</p></div><div class="employee-profile-pic flex-item" data-img-src="'
            +data.employee_info[0][i]['profile_pic']+'"></div>');
          }

          var profile_pic_path = data.employee_info[0][i]['profile_pic'].split('\\').join('\\\\');
          $("#the-team-wrapper .flex-content-wrapper .flex-content .employee-profile-pic:eq("+i+")")
          .css({'background': 'url(_employee_pics/'+profile_pic_path+')',
          'background-repeat': 'no-repeat','background-position': 'center', 'background-size': 'cover'});
        }

      });



      var get_job_title = function(employee_id){
        $.ajax({
          url: 'db_job_title_lookup.php',
          type: 'POST',
          dataType: 'text',
          data:{
            employee_id: employee_id
          }
        }).done(function(data1){
          data1;
      });
      };

嗨,我有这个代码,我在'var get_job_title'函数中使用Ajax从服务器检索一些数据。现在我想在H3元素中使用该文本,如'var get_job_title'函数上面的代码所示,但我得到的只是[object Object]。请帮忙!!!

0 个答案:

没有答案