How to specify an external website for XMLHTTPRequest

When using XMLHTTPRequest in javascript, I want to send it to an external website, not the one where the .js file is located. To send it to test.php on the current server, I would use

request.open("POST", "test.php", true);

but for the second argument, how to send it to another site. "example.com/test.php" searches for the file on the current server, and " http://example.com/test.php " justseems for a complete failure. "

+3
source share
5 answers

You cannot for security reasons. See the same origin policy for JavaScript.

, , .

- , Ajax , , HTTP- . , .

+7

, :)

+6

( ) XmlHttpRequest -. SCRIPT . jQuery ajax.

+1

, . , .

Internet Explorer 8.0 XDomainRequest - , . , , Access-Control-Allow-Origin "*" .

- - , IE8?

+1

, HTTP, .

Access-Control-Allow-Origin: *
+1

Source: https://habr.com/ru/post/1707612/


All Articles