只有HTTP支持跨源请求,但它不是跨域的 [英] Cross origin requests are only supported for HTTP but it's not cross-domain

查看:113
本文介绍了只有HTTP支持跨源请求,但它不是跨域的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码发出AJAX请求:

I'm using this code to make an AJAX request:

$("#userBarSignup").click(function(){
    $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",
        {/*params*/},
        function(response){
            $("#signup").html("TEST");
            $("#signup").html(response);
        },
        "html");

但是从Google Chrome JavaScript控制台我一直收到此错误:

But from the Google Chrome JavaScript console I keep receiving this error:


XMLHttpRequest无法加载
file:/// C:/xampp/htdocs/webname/resources/templates/signup.php.Cross
原始请求仅支持HTTP。

XMLHttpRequest cannot load file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross origin requests are only supported for HTTP.

问题是 signup.php 文件是托管在我的本地网络服务器是运行所有网站的地方所以它不是跨域的。

The problem is that the signup.php file is hosted on my local web server that's where all the website is run from so it's not cross-domain.

如何解决这个问题?

推荐答案

您需要实际运行网络erver,并对该服务器上的URI发出get请求,而不是对文件发出get请求;例如更改行:

You need to actually run a webserver, and make the get request to a URI on that server, rather than making the get request to a file; e.g. change the line:

    $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",

读取如下内容:

    $.get("http://localhost/resources/templates/signup.php",

并且初始请求页面也需要通过http进行。

and the initial request page needs to be made over http as well.

这篇关于只有HTTP支持跨源请求,但它不是跨域的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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