Wikipedia:WikiProject User scripts/Guide/Ajax: Difference between revisions

Content deleted Content added
Fetch page content: Use promises!
Using plain jQuery: Use promises!
Line 67:
$.getJSON(
mw.util.wikiScript('api'),
'format=json&action=query&prop=revisions&rvprop=content&rvlimit=1&titles=Wikipedia:Sandbox',
)
.done(function ( data ) {
var page, wikitext;
try {
for ( page in data.query.pages ) {
for ( page in data.query.pages ) {
wikitext = data.query.pages[page].revisions[0]['*'];
doSomethingWithText( wikitext );
}
} catch ( e ) {
doSomethingInCaseOfError();
}
} catch ( e ) {
doSomethingInCaseOfError();
}
})
).fail( doSomethingInCaseOfError );
</source>