That was a typo in my comment, the code I run was correct. In the code I'm using there was already set up another callAPI function which looked like this:
function callAPI(data, method, callback) {
data['format'] = 'json';
$.ajax({
data: data,
dataType: 'json',
url: wgScriptPath + '/api.php',
type: method,
success: // do some stuff
error: // do other stuff
},
timeout: 10000
});
}
I tried to both use your code and this function by calling it like this:
// Check if AbuseFilter is enabled
var AfQuery = {
'meta': 'siteinfo',
'siprop': 'extensions',
'action': 'query'
};
callAPI(AfQuery, 'GET', function(response) {
var o = response.query.extensions;
var found = false;
var i;
if ($.isArray(o)) {
for ( i = 0; i < o.length && !found ; ++i ) {
found = o[i].name === 'Abuse Filter';
}
}
if (found) {
abuseFilterOn = true;
} else {
abuseFilterOn = false;
}
});
But I had the same result (the functions was correctly executed but couldn't set the variable).
In short I need to run a code like this:
if ( abuseFilterOn ) {
// do stuff
}