AJAX requests made by another domain's javascript file -


have 2 visual studio's running on same computer following urls:

  1. http://localhost:47503 (web api, #1)

  2. http://localhost:12345 (client calls above web api, #2)

client (#2) hard codes site #1's <script src="http://localhost:47503/file.js"></script>. inside file.js single function:

function getdata() { $.ajax({     url: 'http://localhost:47503/api/autos',     type: 'get',     datatype: 'json',     data: { "a": '_1', "b": 'test', "c": "val c" },     success: function (result) {         alert("success");     } }); 

cross-origin request blocked: same origin policy disallows reading remote resource @ http://localhost:47503/api/autos?a=_1&b=test&c=value+c. (reason: cors header 'access-control-allow-origin' missing).

thought since script loaded client #1, invoked client #2 hence bypassing same origin policy in way? script client #1 calls client #1. jsonp , cors known solutions problem want know if above possible.

thought since script loaded client #1, invoked client #2 hence bypassing same origin policy in way?

no, not possible. origin of document, not individual script tags. how able load libraries jquery cdn, make ajax requests own server.


on side note, if origin determined script making call (which never is), code still wouldn't work, since jquery making ajax call.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -