Тема: Jquery request giving an error

Hi,

I'm using JQuery to make a POST request but it's giving this error on the console.

Failed to load http://www.site.com: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

What am i missing?

2 Востаннє редагувалося /KIT\ (08.07.2021 13:50:05)

Re: Jquery request giving an error

Are you sure "http://www.site.com" exist? Show your code.

3

Re: Jquery request giving an error

https://developer.mozilla.org/uk/docs/W … low-Origin
https://stackoverflow.com/questions/845 … low-origin

Подякували: leofun011

4

Re: Jquery request giving an error

/KIT\ написав:

Are you sure "http://www.site.com" exist? Show your code.

I'm using the http://www.site.com as an example. The real purpose is to reach any site.

Also the jquery request works with http://127.0.0.1 using LiteServe http server.
(The realtime log, register the request)

Here the Jquery code that i'm using where "http" is defined by the user and the button calls "myhttp" function.

<script>
function myhttp() {
    var http = document.getElementById("http").value;
    var dataString = 'index.html';
        $.ajax({
            type: "GET",
            url: http,
            data: dataString,
            cache: false,
        });
    }
</script>

Thanks

5 Востаннє редагувалося privateloader (26.03.2018 20:42:46)

Re: Jquery request giving an error

So according with what i just read it doesn't work with Chrome nevertheless using Chrome in http://127.0.0.1 works.

6

Re: Jquery request giving an error

Do not mistake http:// for file:///.

7

Re: Jquery request giving an error

koala написав:

Do not mistake http:// for file:///.

OK, As far as i know html and JavaScript are client languages so theoretically the protocol http:// and file:/// are very similar when using this two languages. Am i wrong?

Also at the console i found another error

Uncaught RangeError: Maximum call stack size exceeded
 at RegExp.test (<anonymous>)
  at Object.trigger (data:text/javascript;|||:3)
 at Function.ajax

I'm using ||| to reduce the line but basically is the JQuery library file in Base64. I'm using URIs to embed JavaScript files into one html file. Will this stop JQuery library from loading?

8

Re: Jquery request giving an error

You are totally wrong.
HTTP is a standard protocol for Web, with tons of big and small adjustments like parameters, statuses, headers, cookies etc.
"file:///" is a pseudo-protocol that simply opens a file on your computer.
Here, because you don't have a Access-Control-Allow-Origin header in your file:/// page, you can't do any additional requests.

"Maximum call stack size exceeded" usually means that you are calling some function recursively, i.e. you call function from itself without ending.

Подякували: privateloader, leofun012