2012-09-20 4 views
3

Ajax jQuery 양식 제출을 구현하려고합니다. 아래에 붙여 넣은 코드가 작동하지 않습니다. 나는 daymonthyear간단한 Ajax 양식 제출 오류

jQuery를 아약스

<script> 
$(document).ready(function() { 
    $('#cal_submit').click(function(event) { 
     if ($('select[name="day"]').val() == '') { 
      event.preventDefault(); 
      alert('Please enter a day'); 
     } 
     else { 
      event.preventDefault(); 
      new_day = $('select[name="day"]').val(); 
      new_month = $('select[name="month"]').val(); 
      new_year = $('select[name="year"]').val(); 
      $.get('function.php', { day: new_day, month: new_month, year:new_year}); 
      $('select[name="day"]').val(''); 
      $('select[name="month"]').val(''); 
      $('select[name="year"]').val(''); 
     } 
    }); 
}); 
</script> 

취급 PHP가 위치한 함수에 대한 정의되지 않은 인덱스 오류가 발생합니다.

function calendar() 
{ 


     $j = mysql_real_escape_string($_GET['day']); 
     $F = ucwords(mysql_real_escape_string($_GET['month'])); 
     $Y = mysql_real_escape_string($_GET['year']); 
     $date =" ".$F." ".$j.", ".$Y." "; 

    $query = "SELECT * 
       FROM calendar 
       WHERE event_day = '".$j."' 
       AND event_month = '".$F."' 
       AND event_year = '".$Y."'" ; 
      $run = mysql_query($query); 
      $norows = mysql_numrows($run); 

      if ($norows < 1){ 
       echo "<div class=\"indexnoresult\">No TAP Event(s) for $date</div>" ; 
      } else { 
      while($row = mysql_fetch_array($run)) { 

        echo "<div class=\"indexnoresult\">Event(s) for $date<br> 
        Name : $row[event_name] <br> 
        Time : $row[event_time] <br> 
        Venue : $row[event_venue] <br> 
        </div> 
       " ; 



      } 

      } ?> 

HTML 양식

 <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" > 

       Pick Date To View Events  

      <select name="day"> 
        <option value =""> </option> 
        <option value ="1">1</option> 
        <option value ="2">2</option> 
      </select> 

    Month 
       <select name="month"> 
        <option value =""> </option> 
        <option value ="january">January</option> 
        <option value ="february"> february </option> 
        <option value ="march">March</option> 
       </select> 

    Year: 
       <select name="year"> 
        <option value =""> </option> 
        <option value ="2005">2005</option> 
        <option value ="2006">2006</option>    
       </select> 

    <input type='submit' name='cal_submit' id='cal_submit'> 
    </form> 
    </div> 

내가 잘못된거야 어디하시기 바랍니다.

+1

MySQL에는 'DATE'유형이 있습니다. –

+0

'new_day, new_month, new_year는 실제로 코드의 어느 위치 에나 값이 할당 되었습니까? –

+0

'new_day'는'new_month'와'new_year'는 무엇입니까? – Deepak

답변

0

에 다음 블록

 day = $('select[name="day"]').val(); 
     month = $('select[name="month"]').val(); 
     year = $('select[name="year"]').val(); 

.

 day = $('select[name="day"]').val(); 
     month = $('select[name="month"]').val(); 
     year = $('select[name="year"]').val(); 
     $.get('function.php', { day: day, month: month, year:year}); 

첫 번째 옵션을 선택 (아약스는 선택 목록에서 선택하지 않고,라고 기본값) 비어, 왜 오류를 이잖아.

또한 양식에 POST 메소드가 표시되는 반면, 아약스는 GET입니다.

0

변경 다음

당신이 당신의 아약스 오브젝트/데이터에서 같은 변수가 필요
 new_day = $('select[name="day"]').val(); 
     new_month = $('select[name="month"]').val(); 
     new_year = $('select[name="year"]').val(); 
+0

감사합니다. 나는 여전히 오류가있다. – ilp

+0

어디에서 오류가 발생합니까? 그것은 PHP에서 무엇입니까? – Deepak

+0

예. function.php – ilp