Wikipedia:WikiProject User scripts/Guide/Ajax: Difference between revisions
Content deleted Content added
remove data sources.... don't think it's needed... |
→Get the wikitext of a page: -superfluous " action: 'query', "; +formatting |
||
Line 31:
=== Get the wikitext of a page ===
Note: <source lang="javascript">
function
/* .. */
alert( 'The wikitext of the page is:\n\n' + wikitext );
}
function
/* .. */
console.log( 'err' );
Line 43 ⟶ 44:
var api = new mw.Api();
api.get( {
prop: 'revisions',
rvprop: 'content',
Line 56:
rv = pg && pg.revisions;
if ( rv && rv[0] && rv[0]['*'] ) {
}
},
err: doSomethingInCaseOfError
} );
</source>
<source lang="javascript">
$.getJSON(
Line 73:
for ( page in data.query.pages ) {
wikitext = data.query.pages[page].revisions[0]['*'];
}
} catch ( e ) {
doSomethingInCaseOfError();
}
}
).fail(
</source>
|