0

I want to access a web service from here in my web application. When the user chooses a species name, the service will inform if the name is valid, the author and year of the name, etc.

First I thought of using Javascript, since the information comes from the user. Then I saw cross-domain restrictions, so I wonder what is the best workaround here. According to this suggestion, I should be using a server-side workaround. But in that case, wouldn't it be easier to just use php curl functions?

Community
  • 1
  • 1
Rodrigo
  • 4,706
  • 6
  • 51
  • 94

2 Answers2

1

Yes.

If you want to do this reliably, do it from a computer you control.

If you are using PHP already, than cURL is the usual HTTP client library.

That said, using PHP/cURL on your server is the server side workaround to cross-origin JS issues, not an alternative to using a workaround.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-2

Try this ajax code.

 $.ajax({   

        url: 'http://localhost/webservice.php?callback=',

        type: "GET/POST",

        data:{data:JSON.stringify([{action:'getUserData', userId: 1234}])},

        dataType: "jsonp",

        crossdomain: true
 });

For more details refer this link HTML-PHP Webservice using the AJAX with crossDomain as TRUE.

Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38
  • $.ajax supposes I'm using jquery? I'm not. When we talk about javascript, no framework should be supposed as "obvious". – Rodrigo Jan 07 '16 at 09:31