Reputation: 10720
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.
Upvotes: 0
Views: 54
Reputation: 61
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.
Upvotes: 2