1

I want to ask, can I access the remote server using pure client side scripting language like Javascript, Jquery, ajax

I want to do but there is CORS problem, We can solve it with server side scripting language but how javascript can help us to do this

1
  • @programmer_1 cross origin resource sharing Commented Feb 27, 2012 at 11:00

1 Answer 1

1

To access a remote server you can either use JSONP to receive data or have the remote server enable CORS, which may not be possibly as you may not have access to it, but if you do this will show you how to enable CORS.

Most web apis support a JSONP request, however. You can use it by passing an additional parameter to the (script-)request and implement a callback function of the same name.

<script src="remote.server.com/api?jsonp=myCallback"></script>

<script>
  function myCallback( data ) {
     // do some stuff
  }
</script>
Sign up to request clarification or add additional context in comments.

7 Comments

How I can check if the remote server is JSONP enabled or not
Either check the API description or try the usual parameters jsonp= or callback= if they return a proper result.
When I tried to check the following error occurs '405 HTTP method GET is not supported by this URL'
Is the API even open for public access via http?
I think you should have a closer look at the API spec then or describe your problem in working with it in more detail.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.