2017-09-05 2 views
0

이 코드를 검사하는 데 하루를 보냈지 만 오류가있는 곳을 찾을 수 없습니다.AJAX가 예상대로 작동하지 않습니다.

<?php 

include('dataconnect.php'); 

if (isset($_POST['classid'])) 
{ 
    $qry = "select * from class where class_id=". $_POST['classid']; 
    $rec = mysql_query($qry); 
    if (mysql_num_rows($rec) > 0) { 
     while ($res = mysql_fetch_array($rec)) { 
      echo $res['class_status']; 
     } 
    } 
} 

?> 

사람이 오류가 어디 정말 그것을 찾을 수있는 날, 알려 수 : 여기

<div class="col-md-6"> 
    <br/> 
    <label for="name">Class ID</label> 
    <select class="form-control" id="csid" name="csid"> 
    <option>----------Please select a Class Code---------</option> 
    <?php 
     $query = $con->query("SELECT * FROM class WHERE class_status='Active' "); 
     $rowCount = $query->num_rows; 
     if($rowCount > 0) { 
     while($row = $query->fetch_assoc()) { 
      echo '<option value="'.$row['class_id'].'">'.$row['class_code'].'</option>'; 
     } 
     } 
     else { 
     echo '<option value="">Class ID not available</option>'; 
     } 
    ?> 
    </select> 
</div> 
<div class="col-md-6"> 
    <br/> 
    <label for="name">Subject Name</label> 
    <input type="text" class="form-control" name="subid" id="subid" disabled/> 
</div> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
<script> 
    $(document).ready(function(){ 
     $('#csid').change(function(){ 
     var classid = $(this).val(); 
     $.ajax({ 
      type:'POST', 
      url:'ajax.php', 
      data:{classid:classid}, 
      success:function(data){ 
      $('#subid').val(data); 
      } 
     }); 
     }); 
    }); 
</script> 

그리고 내 ajax.php 파일입니다. 고맙습니다.

+1

미안하지만 당신이 가진 이슈를 이해하지 못합니다. –

+0

[** 디버깅 **] (https://en.wikipedia.org/wiki/Debugging) 코드를 사용해 보셨습니까? –

+4

또한, mysql_ 생성자는 PHP ** 5.5에서 더 이상 사용되지 않습니다 (https://wiki.php.net/rfc/mysql_deprecation). ** PHP 7에서는 제거 **되었습니다. (https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7#extmysql). [** MySQLi **] (http://php.net/manual/en/book.mysqli.php) 또는 [** PDO **] (http://php.net/manual/)로 전환하십시오. en/book.pdo.php), [** prepared statements **] (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)를 사용하여 [** SQL 인젝션 **] (https://en.wikipedia.org/wiki/SQL_injection). –

답변

관련 문제