Pregunta

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

¿Fue útil?

Solución

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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top