AJAX showing retrieved values as undefined

前端 未结 5 1737
暗喜
暗喜 2021-01-21 00:17

I am using AJAX to send values to PHP and retrieve the values from PHP. The problem is the value i am getting from PHP is viewed as undefined in AJAX. Please help me solve this

5条回答
  •  感情败类
    2021-01-21 00:26

    Because you are encoding your data in json.

    Try adding dataType:"json" in your ajax and ajax has type not method so change to type data should be in {} only:

    $.ajax({
       type:"GET",
       url:"dash2.php",
       dataType: 'json',
       data:{channel:channel},
       success:function(data){
          console.log(data.a);
          console.log(data.b);
          console.log(data.c);
       }
     });
    

    Try putting this line:

    $channel=$_GET['channel'];
    

    after db selection:

    mysql_select_db($dbname);
    

提交回复
热议问题