Motyar

@motyar

Freelance Web Developer

Static Web Hosting, made easy

Jan 3, 2010

Call api with javascript without using ajax

It was really wonderful when i got the way to call an api with javascript. I am not talking about ajax at all. Actually this is the way you can inject a js script in head OR You can ping a uri but you cant get the result back. this can make you avoid some ajax calls.

Its a very simple way following these steps-
1. Create a script element.
2. Set its 'src' attribute according to your api url;
3. Add this 'script' element to 'head'.

The JavaScript

function callApi(api){
var s = document.createElement('script');
s.setAttribute('src',api);
document.getElementsByTagName('head')[0].appendChild(s);
}
var api = 'YOUR HTTP GET URL';
callApi(api);

Related articles

Create a bookmaker with Jquery
Paint like drawing with Jquery
Drawing with canvas and Jquery

Labels: ,




By :