Skip to content Skip to sidebar Skip to footer

AJAX Calls From Local Javascript Code To Remote Server

Is it possible to make AJAX-calls (e.g. using jQuery.ajax() ) from local html/js file (e.g. file://home/a.html) to the remote server (e.g. http://domain:8080/api)? If yes, how to e

Solution 1:

Unfortunately, there are no other ways but use one of 2 methods: either JSONP as stated in previous answers or CORS. Both require server-side changes. JSONP is better if you need older browser's support, but CORS is obviously cleaner and likely doesn't require server-side scripts changes, modifying server configuration should be enough.

Hope this helps.


Solution 2:

Add callback=? at the end of your url which you passing to ajax


Solution 3:

JSONP is the way to go. If you are accessing a third party API, hopefully it will already support it. If it is your own API, you might have to add support for it yourself. You might find this related question helps you get some background: What is JSONP all about?


Post a Comment for "AJAX Calls From Local Javascript Code To Remote Server"