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

Content deleted Content added
Using module mediawiki.api: Use promises here as well..
Line 66:
$.getJSON(
mw.util.wikiScript('api'),
}{
'format=json&action=query&prop=revisions&rvprop=content&rvlimit=1&titles=Wikipedia:Sandbox'
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 ) {
wikitext = data.query.pages[page].revisions[0]['*'];
doSomethingWithText( wikitext );
}
} catch ( e ) {
doSomethingInCaseOfError();
}
})
} catch ( e ) {
.fail( doSomethingInCaseOfError );
doSomethingInCaseOfError();
}
})
.fail( doSomethingInCaseOfError );
</source>