How can I call multiple code behind method from JavaScript?
Currently I am using
But I think first second method is call simultaneously,
what I want, if first method is called successfully then
only second method should be called.
So how can I make this possible?
Code below:
function OnResetDataClick() {
var UserEmail = document.getElementById("ContentPlaceHolder1_UserName1");
var val = UserEmail.value;
var usedata= "";
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (reg.test(val) == false) {
}
else {
var getPassword = {
type: "POST",
url: "GetData.aspx/GetDataMethod",
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
usedata= response.d;
},
error: function (result) {
alert("Error");
}
};
$.ajax(getPassword);
if (usedata!= "") {
var options = {
type: "POST",
url: "GetData.aspx/SendData",
data: "{'toMailAddress':'" + val + "','usefulldata':'" + usedata+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var val1 = response.d;
alert(val1);
},
error: function (result) {
alert("Error in " + result);
}
};
$.ajax(options);
}
}