简体   繁体   English

访问服务器端页面错误

[英]Accessing server side page Error

I am new to web development I have created a project which I host on local Apache Server I developed this project with IE8 browser and Developer tools 我是Web开发的新手,我创建了一个项目,该项目托管在本地Apache服务器上,并使用IE8浏览器和Developer工具开发了该项目。

But now when I open with chrome browser it does not hit the request with error stating as Access-Control-Allow-Origin. 但是现在,当我使用chrome浏览器打开时,它没有显示错误,提示为Access-Control-Allow-Origin。

I read and browsed through stackoverflow sites and web they say its problem of CORS or Same Origin policy after that I got to know that this can be resolved by adding a php script 我阅读并浏览了stackoverflow网站和网站,他们说这是CORS或Same Origin策略的问题,之后我知道可以通过添加php脚本来解决此问题

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

But since I cannot over ride the server side 但是由于我无法超越服务器端

I tried it on my client side page by adding the above script but still it gave the same error Origin http://localhost is not allowed by Access-Control-Allow-Origin. 我通过添加上述脚本在客户端页面上尝试了此操作,但是仍然给出了相同的错误。Access http://localhost is not allowed by Access-Control-Allow-Origin.

I have suppose two pages first Login.html and second SecondPage.html 我假设有两个页面,第一页为Login.html,第二页为SecondPage.html

I have included the above code in Login.html in header part as seen below 我在标题部分的Login.html中包含了上面的代码,如下所示

<!doctype html>

<head>

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

    <!-- Basics -->

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>Login</title>

    <!-- CSS -->

    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" href="css/styles.css">


    <script type="text/javascript" src="js_files/login6.js"></script>

     <script script language="javascript" src="js_files/jquery-1.7.2.min.js"></script>


    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>

<script src="//code.jquery.com/jquery-latest.js"></script>



</head>

Am I right ?? 我对吗 ??

Or should I include the same in SecondPage.html 还是我应该在SecondPage.html中添加相同的内容

Generally, you have to send any headers at the very beginning of your document. 通常,您必须在文档的开头发送任何标头。 And don't foget your opening html-tag. 并且不要弄乱您的开头html标签。 Like this: 像这样:

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

<!doctype html>
<html>
<head>

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

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