drummer
drummer

Reputation: 1221

Javascript jquery to contact an API

I'm trying to connect to a webapi at a location that looks like this from inside my js jquery file.

example.com/?var=input

Is there a simpler way to do it than an ajax call?

Upvotes: 0

Views: 76

Answers (2)

Vamos
Vamos

Reputation: 2801

I would use AJAX for this, but I guess you could open a hidden IFRAME with the URL set to the page you want to connect to (not sure why you would do this though!).

Maybe use a JavaScript library like JQuery to make life easier?

If the data you're trying to access is returned as JSON then you can get around the browser security problems.

Here is a JQuery example where a request is made to Flickr.com from JQuery.com:

docs.jquery.com/Ajax/jQuery.getJSON

Upvotes: 1

jerjer
jerjer

Reputation: 8768

You may be run into cross domain issues if you do it with an ajax call. Call the web-api from serverside, it would be the most appropriate way.

Upvotes: 1

Related Questions