从 angularJs 调用 php 文件

Calling a php file from angularJs

您好,我正在尝试从 angularjs 控制文件中调用 php。

PHP 和控制文件都在相同的文件夹中,并且在 Wampwww 目录中,我这样调用 php

`$scope.url='far_submit.php';`
$http.post($scope.url, {"name": $scope.fname, "email": $scope.email, "lname": $scope.lname}).
                 success(function(data, status) {...}  

我在浏览器中收到类似 XMLHttpRequest cannot load file:///C:/wamp/www/reg/far_submit.php. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

的错误

我哪里做错了?

谢谢。

php 文件应由 Apache, Nginx, IIS 等网络服务器处理和提供。

然后您的 JavaScript 应该使用 Ajax method

调用为 PHP 服务的 URL

你的$scope.url应该是,

$scope.url='http://localhost/reg/far_submit.php';

您的 PHP 文件 far_submit.php 应该以

开头
<?php
  header("Access-Control-Allow-Origin: *");