jquery函数返回true,但无法处理返回值
jquery function returns true but cannot process the return value
嗨,伙计们,这是我为一个函数编写的代码,该函数检查我的数据库中是否存在某个id
function checkifuploaded(citenr) {
$.ajax({
type: "POST",
url: "locationsDB.asmx/checkifexist",
data: '{"citenr": "' + citenr + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d) {
return true;
} else {
return false;
}
//setinfo();
},
failure: function (response) {
alert(response.d);
}
});
}
现在我有另一个函数,它使用上面的函数
function plotnew(lat, lng) {
$('#latt').val(lat);
$('#longt').val(lng);
$("#Panel2").dialog({
resizable: false,
height: 350,
width: 600,
modal: true,
buttons: {
"Plot Incident and Save to Database": function () {
//$(this).dialog("close");
if (checkifuploaded($('#idcr').val())) {
$.post(
'insertcrimelocation.aspx',
{ lat: $('#latt').val(), long: $('#longt').val(), cirsid: $('#idcr').val() },
function (responseText, textStatus) {
//checkifexist
plot();
$("#Panel2").dialog("close");
$.ambiance({ message: "successfully plotted the incident!",
title: "Success!",
type: "success"
});
})
.error(function () {
$.ambiance({ message: "error on request",
title: "Error!",
type: "error"
});
});
} else {
$.ambiance({ message: "The C.I.R.S id is not yet uploaded",
title: "Error!",
type: "error"
});
}
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}
我下面的Web服务代码按预期返回,它返回真实的
<WebMethod()> _
Public Function checkifexist(citenr As String) As Boolean
Dim locs As New crimemsapslocationDataContext
Dim check = locs.OFFENSEs.Where(Function(offense) offense.CITE_NR = citenr).First
If Not check Is Nothing Then
Return True
Else
Return False
End If
End Function
令我惊讶的是,在第二个函数plotnew()上,如果返回值为true,它会以另一种方式执行,而不是通过另一个页面调用函数。我的代码有问题吗?
我让它现在工作代码低于
function checkifuploaded(citenr) {
$.ajax({
type: "POST",
url: "locationsDB.asmx/checkifexist",
data: '{"citenr": "' + citenr + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d) {
i squeezed my function here to make it work
thanks for all the help and info
} else {
return false;
}
//setinfo();
},
failure: function (response) {
alert(response.d);
}
});
}
您可以使用promise对象来处理异步处理。http://api.jquery.com/jQuery.ajax/
相关文章:
- Javascript返回值只在循环中返回一次
- XMLHttpRequest未返回值-状态202
- 使用filedownload jquery插件处理FilePathResult返回值
- 将ActiveXObject返回值转换为JQuery Object以处理XML
- 如何用JavaScript处理SQLite中snippet()的返回值
- 如何获取 jQuery 事件处理程序返回值
- 应该如何处理JavaScript
链接的返回值 - jquery函数返回true,但无法处理返回值
- 如何处理php给出的多行动态返回值
- 如何在nodejs中处理多个回调返回值
- 将函数的返回值传递给事件处理程序
- 在JavaScript中处理对象和创建返回值的方法
- 处理promises nodejs中的返回值
- 如何在javascript中动态调用事件处理程序并获取其返回值
- 如何从jQuery.ajax()中的成功和错误处理程序返回值给父方法?
- 如何在承诺中从事件处理程序返回值
- 覆盖事件处理程序中的返回值
- JavaScript处理onClick返回值
- JavaScript:执行函数顺序 - 在函数完成处理之前嵌套函数返回值
- 在 javascript 中处理多个返回值