AngularJS-从自己的服务器请求PHP脚本返回403 [英] Angularjs - requesting PHP script from own server returns 403

查看:90
本文介绍了AngularJS-从自己的服务器请求PHP脚本返回403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将AngularJS用于我的网站.我不会使用php向我的mysql数据库发出GET请求.我已经创建了一个简单的php脚本

I'm using AngularJS for my website. I wan't to make a GET request to my mysql database using php. I've created a simple php script

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

$conn = new mysqli($server, $username, $password, $database);

mysqli_set_charset($conn, "utf8");
$result = $conn->query("SELECT name FROM table");

$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "") {
        $outp .= ",";
    }
    $outp .= '{"name":"'  . $rs["name"] . '",';
}    
$outp ='{"records":['.$outp.']}';
$conn->close();

echo($outp);
?>

当我使用angularJs http.php请求此php文件时,响应被禁止为403.我的AngularJS代码:

when I request this php file with angularJs http.get the response is 403 forbidden. My AngularJS code:

getScript: function () {
        var req = {
            method: 'GET',
            url: '/app/scripts/script.php',
            headers: {
                'Content-Type': 'application/json'
            }
        };
        return $http(req);
    }

您可以看到,即使来自同一台服务器,我也收到403.我在这里想念什么?

As you can see I get 403 even tho it's from same server. What am I missing here?

推荐答案

好的,我知道了.我的.htaccess文件中的这一行得到了403:

Alright I figured it out. I got 403 due to this line in my .htaccess file:

Options FollowSymLinks

这篇关于AngularJS-从自己的服务器请求PHP脚本返回403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆