我正在尝试通过AJAX调用在php文件中设置会话变量。但是我收到一个未定义的索引错误。
这是jQuery代码:
$('.selectcpno li').click(function(){
//Get the value
var value = $(this).data("value");
//Put the retrieved value into the hidden input
$('input[name=cpnoselected]').val(value);
$.ajax({
type: "post",
url: "../web/cpnoselected.php",
dataType: "text",
data:"{'cpno':'" +value+ "'}",
success: function( data ){
alert("hellosuccess");
document.getElementById("cpno").innerHTML=data;
},
error: function( jqXhr, textStatus, errorThrown ){
alert(value);
console.log( errorThrown );
console.log( jqXhr );
console.log(textStatus);
}
});
});
这就是我在php文件中的内容:
include("../config/config.php");
include("../inc/functions.php");
$cpnoselected= $_POST['cpno'];
$_SESSION['cpno']=$cpnoselected;
echo $cpnoselected;
?>
当我运行它时,我得到未定义的索引:C:/...../ cpnoselected.php中的cpno
请协助解决