This is an answer about accessing resource cross-domain:
The XHR is constrained by cross-domain rules; to use JSONP you need to add a script element: function func_callbk() { console.log(arguments); } var s = document.createElement('script'); s.type = 'text/javascript'; s.src = 'http://abhishekprakash.com/script/example.json?callback=func_callbk'; var h = document.getElementsByTagName('script')[0]; h.parentNode.insertBefore(s, h); As pointed out by Ian in the comments, the proper response of your server should be something like this: func_callbk('hello world') Questions:
- If you cannot access resources cross-domain then this resource would not be accessible or at least the browser would not allow the domain to access the other domain:
s.src = 'http://abhishekprakash.com/script/example.json?callback=func_callbk';is that correct? - A compliant server in the handshake should return a String of
func_callbk('hello world')when the above resource is accessed?