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

                failure:
                alert("failure");
            });
}

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

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.

http://api.jquery.com/jquery.getjson/

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

$.getJSON(url2)
    .done(function (json) {
        console.log(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, privacy policy and cookie policy

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