dobby
dobby

Reputation: 229

Javascript json callback

what does

script.setAttribute('src', '/json?callback=loadJsonPhotos');

JavaScript code mean?

Upvotes: 0

Views: 3706

Answers (3)

luchopintado
luchopintado

Reputation: 939

This script is equivalent to write the following html code:

<script src="/json?callback=loadJsonPhotos"></script>

Upvotes: 0

Bot
Bot

Reputation: 11855

It sets the src attribute of the html for script to /json?callback=loadJsonPhotos

Upvotes: 0

Peter Sobot
Peter Sobot

Reputation: 2557

That's a little snippet of code to set the src (source) attribute of a Javascript include tag to /json?callback=loadJsonPhotos. Once that line of code runs, the browser will fetch the data from that URL and execute the script that returns. The data that script returns will be wrapped in a function like so:

loadJsonPhotos({data: "blah"});

All you need to do to use that data is write a function called loadJsonPhotos that will be called once the data has loaded.

Upvotes: 4

Related Questions