【问题标题】:Un-Defined index with $http.使用 $http 的未定义索引。
【发布时间】:2014-06-06 15:29:13
【问题描述】:

不知道为什么我在下面的代码中得到了未定义的索引。我检查了所有内容,但找不到问题所在。

   $http({
    url: "php/mainLoad.php",
    method: "GET",
    data: {"userId":"1"}
    }).success(function(data, status, headers, config) {

        console.log(data);
    }).error(function(data, status, headers, config) {
       // $scope.status = status;
       alert(status);
    });

php

echo $_GET['userId'];

【问题讨论】:

  • Emmm,奇怪的东西,什么显示 var_dump($_REQUEST);一般?
  • 你试过params: {userId:"1"}吗?或者你确定 url 返回一个未定义的数据?

标签: javascript php angularjs


【解决方案1】:

您的ajax 上的参数data 期望方法是POST,如果您需要通过$_GET 获取它,请改用params

$http({
    url: "php/mainLoad.php",
    method: "GET",
    params: {"userId":"1"}   // Change to `params` from `data`.
}).success(function(data, status, headers, config) {

    console.log(data);
}).error(function(data, status, headers, config) {
    // $scope.status = status;
    alert(status);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多