function checkUserRole(userName){
    var url2 = _spPageContextInfo.webServerRelativeUrl + 
"/_vti_bin/ListData.svc/MyList?select=*&$filter=Email eq '"+userName+"'";


I'm calling this function from the success event of another function (the one that gets the value for userName). When this function executes, BOTH the success and failure fire. I've tried multiple re-writes of the syntax and it always happens, but I'm at a loss for why it would happen. Any suggestions?

1 Answer 1


You actually only have defined one callback and that's the success callback, and it's executing both the alerts. JavaScript is interpreting those 'success' and 'failure' bits as labels - an obscure JS construct nobody uses - not as parameters of getJSON.

Take a look at the documentation for getJSON.


This example, copied right from the docs above, shows how to define a success and fail handler and log the data from them.

    .done(function (json) {
    .fail(function (jqxhr, textStatus, error) {
        var err = textStatus + ", " + error;
        console.log("Request Failed: " + err);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.