Wikipedia:WikiProject User scripts/Guide/Ajax: Difference between revisions
Content deleted Content added
Fix: the result is on "data.edit.result", not on "data.result" |
→Edit a page and other common actions: Updated to use mw.user.tokens.get( 'editToken' ) from MW 1.18 instead of an extra API call |
||
Line 28:
The code below shows how to edit a page, but it can easily be adapted to other actions by reading the [{{SERVER}}/w/api.php API documentation].
<source lang="javascript">
});▼
// Edit page (must be done through POST)
function
var mySandbox = 'User:' + mw.config.get( 'wgUserName' ) + '/Sandbox';▼
$.ajax({
url: mw.util.wikiScript( 'api' ),
Line 65 ⟶ 37:
format: 'json',
action: 'edit',
title:
text:
summary: info.summary,
summary: 'Trying to edit my sandbox [[Project:WikiProject User scripts/Guide/Ajax|using AJAX]]...',▼
token:
},
success: function( data ) {
Line 82 ⟶ 54:
});
}
editPage({
text: 'Cool! It works! :-) ~~' + '~~',
▲
▲});
</source>
|