简体   繁体   English

Angularjs将URL数据发布到PHP并打印响应

[英]Angularjs POST URL data to PHP and print the response

I have written the code but not getting output. 我已经编写了代码,但没有得到输出。 How can I print the output on the page using AngularJS? 如何使用AngularJS在页面上打印输出?

When I am using the dynamic URL, the active link color change isn't working. 当我使用动态网址时,活动链接的颜色更改不起作用。

// Grab path parameters and query parameters
var routeParameters = $routeParams;
$scope.pageParameter = (routeParameters["pageParam"] || "No page parameter");
$scope.queryParameter = (routeParameters["queryParam"] || "No query parameter");

// Do an $http call to your site
$http({
    url: "http://keralapsctuts.com/app/index.php",
    method: "POST",
    data: {
        param1: $scope.pageParameter,
        param2: $scope.queryParameter
    }
}).success(function(response) {
    $scope.values = reponse;
});

The response object represents your HTTP response coming back. response对象表示您返回的HTTP响应。 I think you should only be assigning the data to you scope values property. 我认为您应该只将数据分配给您的作用域值属性。 So update it like so: 所以像这样更新它:

.success(function(response){
    $scope.values = reponse.data;
    console.log($scope.values); // print to console.
});

If you want to display in the view, @tokkov show how in his answer. 如果要在视图中显示,请@tokkov在其答案中显示操作方法。

You'd have to reference the values variable within your page template. 您必须在页面模板中引用values变量。 So something like: 所以像这样:

<div ng-repeat="value in values">
A: {{value.a}} B: {{value.b}}
</div>

Obviously the specifics would depend on what the response data looks like and how you want to display it. 显然,具体情况取决于响应数据的外观以及您希望如何显示。

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

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