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

Content deleted Content added
m Code: updated
Line 51:
ajax_get('http://example.com', show_result);
function show_result(_api) {
if(_api==null.success)
alert('An error occurred.');
else
alert('The remote page contains:\n' + api.responseText);
else
alert('An error occurred.');
}
</source>
Line 86:
// edit page (must be done through POST)
function edit_token(_token) {
var parameters = 'action=edit&title=User:Pathoschild/Sandbox&text=AJAX_test!&token=' + encodeURIComponent(_token);
api.open('POST', wgServer + '/w/api.php', true); // just reuse the same query object
api.onreadystatechange = alert_result;
Line 112:
ajax_edit_token('edit', edit_page);
function edit_page(_token) {
var parameters = 'action=edit&title=User:Pathoschild/Sandbox&text=AJAX_test!&token=' + encodeURIComponent(_token);
ajax_post(wgServer + '/w/api.php', parameters, alert_result);
}
function alert_result(_api) {
if(_api.success)
if(_api==null) alert('An error occurred.');
else alert('Page edited!');
else
if(_api==null) alert('An error occurred.');
}
</source>