无法运行AJAX请求

Avn*_*ain 1 php ajax jquery

我正在尝试通过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);

                }
            });
        });
Run Code Online (Sandbox Code Playgroud)

这就是我在php文件中的内容:

<?php

 include("../config/config.php");
 include("../inc/functions.php");

 $cpnoselected=  $_POST['cpno'];
 $_SESSION['cpno']=$cpnoselected;
 echo $cpnoselected;
 ?>
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到未定义的索引:C:/...../ cpnoselected.php中的cpno

请协助解决

Ana*_*Die 7

更改

data:"{'cpno':'" +value+ "'}",// it needs to be object not string
Run Code Online (Sandbox Code Playgroud)

data:{'cpno':value}, //now its object
Run Code Online (Sandbox Code Playgroud)