2012-08-13 2 views
0

이 jquery 스 니펫이 있습니다. 나에게 가치를 전달하지 않기 때문에, 나는 무슨 일이 일어나고 있는지를보기 위해 함수 호출을 포함하여 왜 그런지 알아내는 모든 종류의 방법으로 갈 것이다. 그러나 아무것도 표시되지 않습니다.Jquery가 아무 반응이 없음

<?php echo form_open('control_form/add_all'); ?> 
     <label for="country">Country<span class="red"></span></label> 
     <select id="country" name="country"> 
      <option value="">Select</option> 
      <?php 

       foreach($result as $row) 
       { 
       echo '<option value="' . $row->pais_id . '">' . $row->pais_name . '</option>'; 
       } 

      ?> 
     </select> 

그리고 다른 예 :

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() 
     { 
      $('#country').change(function() 
        { 
        if ($(this).val()!='') 
         { 
           $("#loquesea").load("/not-here.php", function(response, status, xhr) 
            { 
           if (status == "error") 
             { 
              var msg = "Sorry but there was an error: "; 
              $("#error").html(msg + xhr.status + " " + xhr.statusText); 
              } 
           }); 


         }); 
        }); 

       }); 



</script> 
</head> 
<body> 
<b>Successful Response (should be blank):</b> 
<div id="success"></div> 
<b>Error Response:</b> 
<div id="error"></div> 


<form action=""> 
<select id = "country" name="country"> 
<option value="volvo">Volvo</option> 
<option value="saab">Saab</option> 
<option value="fiat">Fiat</option> 
<option value="audi">Audi</option> 
</select> 
</form> 
</body> 
+1

Chrome 개발자 도구의 네트워크 탭 또는 방화 광의 Net 탭에서 요청이 실제로 전송되는지 여부와 반환 항목을 확인하십시오. –

+0

예상대로 선택 목록을 사용하면 아무 일도 일어나지 않습니다. – iaintunderstand

답변

1

$(document).ready(function() { 
    $('#country').change(function() { 
     if ($(this).val() != '') { 
      $("#loquesea").load("/not-here.php", function(response, status, xhr) { 
       if (status == "error") { 
        var msg = "Sorry but there was an error: "; 
        $("#error").html(msg + xhr.status + " " + xhr.statusText); 
       } 
      }); 
     } 

     }); 
    }); 
+0

그것은 OP가 요구 한 것이 아니 었습니다. 게다가 HTML의 나머지 부분에 그러한 요소가 있는지는 알 수 없습니다 (나머지 부분은 게시하지 않았습니다). 어쨌든 문제는 값이 반환되지 않는다는 것입니다. 구문 오류로 인해 발생했을 가능성이 큽니다. – Cranio

+0

예 이것도 하나 더 추가 한 문제 중 하나입니다 – Adil

+0

예, 이미 내 downvote를 제거했습니다. 두 번째 HTML을 보지 못했습니다. 죄송합니다. – Cranio

1

많은 오류가 있습니다 두 개의 서로 다른 예

<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 
//jquery code for source list 
$(document).ready(function() 
    { 
     $('#country').change(function() 
     { 
      if ($(this).val()!='') 
       { 
       $("#source").load("/CI-3/application/controllers/control_form.php", {pais_id: $(this).val()}, function() 
      { 
      alert('Load was not performed.')); 
      } 

    }); 

}); // end of country and city function 
</script> 

그래서이 변화하는 값시 jQuery를 활성화해야 selectList의입니다 괄호. 문제를 해결하면 코드가 작동합니다. 올바른 들여 쓰기를 가이드로 사용하십시오. 이 $("#source")

변경

$("#source") 

$("#success") 

에 당신의 선택은 } 브래킷 if ($(this).val() != ''){ 누락 된 있도록 ID 소스와 HTML의 요소가 없다

$(document).ready(
    function() 
    { 
     $('#country').change(
      function() 
      { 
       if ($(this).val()!='') 
       { 
         $("#source").load("/CI-3/application/controllers/control_form.php", 
              {pais_id: $(this).val()}, 
              function() 
                { 
              alert('Load was not performed.'); // 1st fix 
               } 
             ); // 2nd fix 

        } 
       } // 3rd fix... and so on 
관련 문제