Topic on Project:Support desk

How to check if rollback succeeded?

5
Guycn2 (talkcontribs)

Hello, I want to rollback a page using JavaScript. for that, I use the following syntax:

new mw.Api().postWithToken('rollback', {
   action: 'rollback',
   title: 'pageName',
   user: 'userName'
});

If the rollback has not succeeded (e.g., if the user does not have the necessary right), I would like to display an error message. How can I check if the rollback has been succeeded?

Ciencia Al Poder (talkcontribs)
Guycn2 (talkcontribs)

@Ciencia Al Poder: Thank you, but I didn't understand how can I get the returned parameters using JavaScript. I tried the following:

new mw.Api().postWithToken('rollback', {
    action: 'rollback',
    title: 'pageName',
    user: 'userName'
}).then(function (data) {
    if (data && data.error) {
        alert( data.error[info] );
    }
});

If the rollback fails, I expect to see an alert box with the error message; however, nothing happens...

Ciencia Al Poder (talkcontribs)

According to the documentation, you should use .done()

Try to add console.log( data ); and see the console output for the details

Guycn2 (talkcontribs)

Thanks, I've succeeded!

Reply to "How to check if rollback succeeded?"