For many days I have been trying to understand 2 things:

  1. The fundamental difference is Json from Jsonp when querying? The fact that Jsonp is a Json shim is more or less clear, but when cross-domain queries, why can't Json be ordinary?
  2. Why use for example Java, for example with its class HttpRequest, etc. There are no problems with Post requests to Api or to server-side .php files, and if you write a client in javascript (jquery) you need to think through something, i.e. if I understand correctly, in languages ​​such as Java there is no such thing as a crossdomain, is the whole inquiry procedure standard, and the response will come anyway?
  • If you are given an exhaustive answer, mark it as correct (tick the selected answer). - Mikhail Vaysman

1 answer 1

The answer is simple - it's all for safety. Since JavaScript works on the user's side, browser developers try to protect the user from harmful code.

  1. The browser can download and execute a script located on another server, but cannot make a request to another server. jsonp is json wrapped in a function call. That is, the browser will download this file and try to run the function. The function itself must be described earlier.

  2. Both PHP and Java (with the exception of the applet) are executed outside the browser and therefore they have no such restrictions. Moreover, if you run javascript on Node.js, then there will also be no such restrictions.

  3. Java applet is also limited. So it must also be signed in order for the browser to launch it.

  • Thanks for the good answer, only one thing is not clear, for example, there are Web services all kinds of APIs, let's say google, vsk or some other, how the browser interacts with them, essentially the same cross-domain queries ????? If so, how do they bypass the security of everything ?? - GoodRA
  • No They do not bypass. You can add CORS and allow cross-domain queries. - Mikhail Vaysman
  • Ie, for example, Google map v2 API-uses CORS ?? In order to be able to use it ... - GoodRA
  • You can always edit your posts: to do this, just use the edit link under the text of your post. Important information is best included directly in the original message. - Mikhail Vaysman
  • Specify exactly which requests to the Google map API you have in the form - Mikhail Vaysman