Im a newbie and currently developing a website but I dont know how to connect to an API. Request and response is via JSON. Thanks for the help!
Im a newbie and currently developing a website but I dont know how to connect to an API. Request and response is via JSON. Thanks for the help!
Try using $.ajax() from jQuery
read more about ajax or better yet, use frameworks like jQuery..
I tried using ajax but the thing is I always get this error No "Access-Control-Allow-Origin" . Would curl be okay to connect to an API? I also use it however the response is the UI of the API. I have a third party username and password to authenticate and the response would be a sessionID if I directly input it to the API. I tried to send a request with the data and use post method in curl. Status is 200 but unfortunately i got the UI as a reponse. I badly need your help guys. Thanks!
download the api library., install curl...
follow the manual.
use JQuery framework.
using curl meaning you would be doing it on the server side.. using ajax, you'll be doing it at client side.. so better think of which is which, depende sa imong situation.. and Access-Control-Allow-Origin means you are not allowed to access the site using the current domain you are using in (my guess would be localhost).. find a way to work around with that..
I had that problem before creating my first Rest-FUL web service. Your app should be in the same domain with your "API"... If you're the one creating your "API" you should be implementing CORS (cross-origin resource sharing) sa server side in that way the service will include the Access-Control-Origin sa server's header response. This is not the problem sa client side, sa server side ni.
In your case check the documentation sa imong third party web service if kung inig hatag nila ug SessionID sa imong App kay ma apil na sa white list sa ilang server imong domain sa imong app.
Have you tried putting this one "$.support.cors =true;"?
love to watch this topic.
you can use php curl for that or jquery ajax and jason..pero depende sa imung api gi gamit
Unfortunately I am not the one who develop the API they only provide me with the URL of the API, third party username and password to test it directly to their API and see what is the sample result. We don't share the same domain, but they white listed my Public IP Address and the IP of the domain of my site to connect to the API. Request and response is via JSON so I would prefer on AJAX. Akong gamiton nga dataType is jsonp? or mu depende pud sa gigamit sa API? hmmm?? dayun application/javascript ang contentType.?
Similar Threads |
|