繁体   English   中英

PHP注意:$ _GET中的未定义索引

[英]PHP Notice: Undefined index in $_GET

我一直在尝试为我的Web应用程序完成服务器端脚本,并且遇到了我似乎无法解决的问题。

我正在使用GET请求从服务器发送/接收数据。 直到我实现了最后一个GET请求,代码都运行良好。 现在我有了PHP Notice: Undefined index: role错误日志中的PHP Notice: Undefined index: role ,我无法弄清原因。

这是PHP服务器端代码。

$handler = new XMLHandler();
if ($_GET["ajax"] == "true") {#fn - Function
    if($_GET["fn"] == "init"){
    }elseif($_GET["fn"] == "cou"){
        echo $handler->toJSON($handler->getCourses());
    }elseif($_GET["fn"] == "mod"){
        echo $handler->toJSON($handler->getModules($_GET["data"]));
    }elseif($_GET["fn"] == "filt"){
        $breakdown = explode(":", $_GET["role"]);//breakdown the roleString from the client side into an Array
        echo $handler->toJSON($handler->getCoursesByRole($breakdown[1]));
    }
}

这是JQuery AJAX调用

var data = {
  "fn" : "filt",
  "ajax" : "true",
  "role" : roleString
};
$.ajax({
  type: "GET",
  url: SERVICE_URL, //Relative or absolute path to response.php file
  data: data,
  contentType: "application/json",
  success: function(response) {
    console.log(response);
    var i, list = "";
        for (i = 0; i < response.length; i++) {
            console.log(response[i]);
            list += formatListItem(response[i]);
        }
        $("#cList").html(list).listview('refresh');
    }
});

}

roleString看起来像这样: core:false:false

如果有人可以提供任何建议或帮助,我将不胜感激。

$ _GET的var_dump给我这个:

array(3) {
  ["fn"]=>
  string(4) "filt"
  ["ajax"]=>
  string(4) "true"
  ["role"]=>
  string(34) "adultScotland:projectM:false:false"
}
[]

在expload之前使用if语句

if($_GET['role']) {
    explode(":", $_GET["role"]);
}

您正在检查所有其他GET变量,但不是这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM