hi guys here is my code for a function that checks if a certain id is present in my database
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);
}
});
}
now i have a another function which is using the function above
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");
}
}
});
}
my webservice code below returns as expected it returns true
<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
what amazes me is that on the second function namely plotnew() if the return value is true it executes the other way around instead of calling a function trough another page is there something wrong with my code?
i got it to work now code below
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);
}
});
}