2014-02-19 3 views
0

모든 답변을 통해 검색했지만 작동하지 않습니다. ajax에서 php로 두 개의 정수 값을 보내려고합니다.PHP가 Ajax에서 값을 가져 오지 못합니다.

다음은 아약스 일부입니다

$(document).ready(function(){ 

    $('input[type="radio"]').click(function(){ 
      var id_user=$(this).filter(':checked').val(); 
      var stringname=$(this).attr('name'); 
      var substr = stringname.split('_'); 
      var id_paper=substr[1]; 
      alert('User_id is: '+id_user +'. And paper_id is: '+id_paper); 

      $.ajax({ 
      type: "POST", 
      url: "ajax/expositor.php", 
      data: {ID_ponencia: id_paper, ID_Participante: id_user}, 
      //contentType: "application/json; charset=utf-8",//type of response 
      //contentType: "application/x-www-form-urlencoded;charset=utf-8", 
      //dataType: "json", 
      beforeSend:function(){ 
       alert('This is AJAX. The following is about to be sent. paper:'+id_paper+' user: '+ id_user); 
      }, 
      success:function(response){ 
       var msj='#msj_'+id_paper; 
       $(msj).append(response); 
      }, 
      error:function (xhr, ajaxOptions, thrownError){ 
       alert(xhr.status); 
       alert(thrownError); 
      } 
      }); 
    }); 
}); 

내가 자료형의 contentType의 주석 부분과 시도하고 그 중 하나가 작동하지 않습니다.

다음은 PHP 코드입니다.

if(isset($_POST["ID_ponencia"]) && !empty($_POST['ID_ponencia']) && isset($_POST['ID_participante']) && !empty($_POST['ID_ponencia'])) 
{ 
    $ID_participante=$_POST['ID_participante']; 
    $ID_ponencia=$_POST['ID_ponencia']; 
    echo ('<p style="color: green;">Success! ☺</p>'); 
}else{ 
    //Output error 
    echo ('<p style="color: red;">error!</p>'); 
    header('HTTP/1.1 500 There has been an error!'); 
    exit(); 
} 

PHP는 PHP 스크립트에 게시 된 html 양식을 테스트 했으므로 잘 작동합니다. 그리고 성공적인 메시지를 받았습니다. 그러나 아약스 스크립트에서 나는 500 오류가 발생합니다.

도움이 될 것입니다.

+2

브라우저의 콘솔 도구를 사용하여 요청/응답주기를 보았습니까? 그 과정에서 오류가 나타납니다. –

답변

2

아약스가 ID_Participante (대문자 P)의 매개 변수를 설정하고 있지만 php가 ID_participante (소문자 p)를 확인 중입니다.

또한 ID_ponencia가 두 번 비어 있지 않은지 확인하고 있습니다. 두 번째 ID_ponencia가 ID_participante를 확인해야한다고 생각합니다.

+0

Ooooppsss !!! 오 예, 그것은 트릭을했다! !! ☺ 거룩한 대문자와 소문자! – Pathros

관련 문제