Javascript is limited when making ajax requests outside of the current domain.
- Ex 1: your domain is example.com and you want to make a request to test.com => you cannot.
- Ex 2: your domain is example.com and you want to make a request to inner.example.com => you cannot.
- Ex 3: your domain is example.com:80 and you want to make a request to example.com:81 => you cannot
- EX 4: your domain is example.com and you want to make a request to example.com => you can.
Javascript is limited by the "same origin policy" for security reasons so that a malicious script cannot contact a remote server and send sensitive data.
jsonp is a different way to use javascript. You make a request and results are encapsulated into a callback function which is run in the client. It's the same as linking a new script tag into the head part of your html (you know that you can load scripts from different domains than yours here).
However, to use jsonp the server must be configured properly. If this is not the case you cannot use jsonp and you MUST rely on a server side proxy (PHP, ASP, etc.). There are plenty of guides related to this topic, just google it!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…