php ajax取不到值,PHP没有从Ajax获取值
我一直在搜索所有的答案,但我無法讓它工作。
我想從ajax發送兩個整數值到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);
}
});
});
});
我已嘗試使用dataType和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 ('
Success! ?
');}else{
//Output error
echo ('
error!
');header('HTTP/1.1 500 There has been an error!');
exit();
}
PHP工作正常,因為我已經測試了一個html表單發布到該PHP腳本,我得到了成功的消息。但是,從ajax腳本中我得到500錯誤。
任何幫助都將非常感激。
總結
以上是生活随笔為你收集整理的php ajax取不到值,PHP没有从Ajax获取值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英汉词典开发文件
- 下一篇: 我的数据分析师转型之路,从零到阿里数据分