JQUERY

    셀렉트(select) change Ajax 이벤트
    • 조회수 2,160
    • 작성일 2016-06-13
    •  
      $("#yj_saupso").change(function() {
        var yjTEXT = $(this).val();
        var yjCOM = $("#yj_com");
        //alert(yjTEXT);
        $.ajax({
          url:'ajax_company_check.php',
          type:'POST',
          data: {
              'reg_xxx': yjTEXT
          },
          cache: false,
          async: false,
          dataType : 'json',
          success: function(res) {
            //alert(res);
            $(yjCOM).children().remove();
            $(yjCOM).append("<option value=''>##신규##</option>");
            for(var i=0; i<res.length; i++) {
              var mcCode = res[i][1];
              var mcName = res[i][0];
              $(yjCOM).append("<option value='"+mcName+"|"+mcCode+"'>"+mcName+"</option>");
            }
          }
        });
      });


    ※ ajax_company_check.php

    $source_text = array();

    $yj_sql = " select yj_1, yj_2 from TABLENAME where yj_6='$reg_xxx' group by yj_1 ";
    $yj_result = sql_query($yj_sql);
    while ($yj_row = sql_fetch_array($yj_result)) {
      $yj1 = $yj_row[yj_1];
      $yj2 = $yj_row[yj_2];
      $source_text[] = $yj1."|".$yj2;
    }

    for($i=0; $i<count($source_text); $i++) {
      $company_list[$i] = explode('|', $source_text[$i]);
    }

    echo json_encode($company_list);