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 Answer 1

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); }); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.