通过基于字段名称的ajax回调填充标题字段

时间:2017-07-22 15:37:10

标签: php jquery

我正在尝试在ajax调用之后填充所有h6字段。一切都有效,除了填充h6字段的h6.each函数。剧本哪里出错?

HTML

<div id="box-profile"">
  <h6 class="text-muted" name="first_name">
  <h6 class="text-muted" name="title"></h6>
  <h6 class="text-muted" name="phone"></h6>
  <h6 class="text-muted" name="fax"></h6>
  <h6 class="text-muted" name="email"></h6>
</div>

SCRIPT

$.ajax({
   type:'POST',
   url:'sql/ajax-load.php',
   data:{account_list:account_list},
   success: function(response){
     var data = JSON.parse(response);
     var titles = $('h6').each(function(){
       var json = data[this.name];
       if(json !== ""){
         this.text = json;
       }else{
         this.text = '';
       }
     console.log(json + err);
   };
  });

PHP

  $account_list = $_POST['account_list'];  
  $sql = $DB_CON_A->prepare("SELECT * FROM staffs WHERE account=:account_list");
  $sql->bindValue(':account_list', $account_list, PDO::PARAM_STR);
  $sql->execute();
  $staff = $sql->fetch(PDO::FETCH_ASSOC);
  die(json_encode($staff));

0 个答案:

没有答案