사용자:BANIP/common.js: 두 판 사이의 차이
백괴게임>BANIP (새 문서: console.log("sfsf");) |
백괴게임>BANIP 잔글편집 요약 없음 |
||
1번째 줄: | 1번째 줄: | ||
console.log(" | var token; | ||
$.ajax({ | |||
url:"/w/api.php?action=query&meta=tokens", | |||
success:function(v,i){ | |||
var datas = JSON.parse($(v).find("pre").text()); | |||
console.log(datas["query"]["tokens"]["csrftoken"]); | |||
token = datas["query"]["tokens"]["csrftoken"]; | |||
} | |||
}) | |||
function changeDocument( title, summary, content, editToken ) { | |||
$.ajax({ | |||
url: mw.util.wikiScript("api"), | |||
data: { | |||
format: 'json', | |||
action: 'edit', | |||
title: title, | |||
summary: summary, | |||
text: content, | |||
token: editToken | |||
}, | |||
dataType: 'json', | |||
type: 'POST', | |||
success: function( data ) { | |||
if ( data && data.edit && data.edit.result == 'Success' ) { | |||
window.location.reload(); // reload page if edit was successful | |||
} else if ( data && data.error ) { | |||
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); | |||
} else { | |||
alert( 'Error: Unknown result from API.' ); | |||
} | |||
}, | |||
error: function( xhr ) { | |||
alert( 'Error: Request failed.' ); | |||
} | |||
}); | |||
} | |||
function addDocument( title, summary, content, editToken ){ | |||
var originContent; | |||
$.ajax({ | |||
url:"/w/index.php?title=" + title + "&action=edit", | |||
success:function ajaxSucess(data){ | |||
originContent = $(data).find("textarea").html(); | |||
}, | |||
async: false | |||
}) | |||
changeDocument( title, summary, originContent + content, editToken ); | |||
} |
2017년 5월 17일 (수) 22:15 판
var token;
$.ajax({
url:"/w/api.php?action=query&meta=tokens",
success:function(v,i){
var datas = JSON.parse($(v).find("pre").text());
console.log(datas["query"]["tokens"]["csrftoken"]);
token = datas["query"]["tokens"]["csrftoken"];
}
})
function changeDocument( title, summary, content, editToken ) {
$.ajax({
url: mw.util.wikiScript("api"),
data: {
format: 'json',
action: 'edit',
title: title,
summary: summary,
text: content,
token: editToken
},
dataType: 'json',
type: 'POST',
success: function( data ) {
if ( data && data.edit && data.edit.result == 'Success' ) {
window.location.reload(); // reload page if edit was successful
} else if ( data && data.error ) {
alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );
} else {
alert( 'Error: Unknown result from API.' );
}
},
error: function( xhr ) {
alert( 'Error: Request failed.' );
}
});
}
function addDocument( title, summary, content, editToken ){
var originContent;
$.ajax({
url:"/w/index.php?title=" + title + "&action=edit",
success:function ajaxSucess(data){
originContent = $(data).find("textarea").html();
},
async: false
})
changeDocument( title, summary, originContent + content, editToken );
}