0

I have been searching through all the answers here but i can't get it to work. I want to send two integer values from ajax to php.

Here is the ajax part:

    $(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);
            }
          });
    });
});

I have tried with the commented parts of dataType and contentType and it doesn't work either.

Here is the php code.

    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();
}

The php is working fine, since i have tested an html form posting to that php script and i get the successfull message. However, from the ajax script i get the 500 error.

Any help will be really appreciated.

1
  • 2
    Have you tried watching the request / response cycle using your browser's console tools? That should reveal any errors in the process. Commented Feb 19, 2014 at 19:56

1 Answer 1

2

Your ajax is setting param of ID_Participante (capital P), but php is checking for ID_participante (lowercase p).

Also, you're checking if ID_ponencia is not empty twice...think you meant for the second one to be checking ID_participante.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.