jquery ajax should call testing(propertyLevelId) function.
function name(roleId) {
$.ajax({
url: '../UserManagement/GetRoleLevel' + '/?role开发者_开发百科Id=' + roleId,
type: "POST",
dataType: "json",
contentType: 'application/json',
//async: false,
success: function (result) {
$.each(result, function (key, value) {
alert(value.Value);
propertyLevelId = value.Value;
testing(propertyLevelId);//It doesnt call the function
},
complete: function () { },
error: ServiceFailed// When Service call fails
});
}
function testing(propertyLevelId) {
alert(propertyLevelId);
}
If you look at your JavaScript console, you should see a syntax error, as your ajax block is incomplete. You never finish the anonymous function you're passing into each
and the closing paren and semi on the each
call:
success: function (result) {
$.each(result, function (key, value) {
alert(value.Value);
propertyLevelId = value.Value;
testing(propertyLevelId);//It doesnt call the function
// ===> here <===
},
It helps if you consistently indent your code, so you can see those kinds of typos more easily.
Here's a fixed version:
function name(roleId) {
$.ajax({
url: '../UserManagement/GetRoleLevel' + '/?roleId=' + roleId,
type: "POST",
dataType: "json",
contentType: 'application/json',
//async: false,
success: function (result) {
$.each(result, function (key, value) {
alert(value.Value);
propertyLevelId = value.Value;
testing(propertyLevelId);//It doesnt call the function
});
},
complete: function () { },
error: ServiceFailed// When Service call fails
});
}
As a side note, unless you're declaring propertyLevelId
somewhere in an enclosing scope that you haven't shown (I'm not talking about the argument to testing
with the same name, I'm talking about the variable you use in your anonymous success
function), you're falling prey to The Horror of Implicit Globals.
精彩评论