My javascript code includes a function called GetRequest() which communicates with the server using $.ajax() to receive a json string:
function GetRequest(ThePage) {
RequestedPage = parseInt(ThePageNumber,10);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../Pages/MyPage.aspx/GetPage",
data: "{'ThePage':'" + ThePageNumber + "'}",
dataType: "json",
success: function (msg) {
var data = msg.hasOwnProperty("d") ? msg.d : msg;
OnSucessCallBack(data);
},
error: function (xhr, status, error) {
alert(xhr.statusText);
}
});
};
Additionally, I have a function named ShowData() that relies on GetRequest() but needs to wait for its data before proceeding:
function ShowData() {
//some code to determine the page number
GetRequest(ThePageNumber);
//need to pause execution until data is retrieved
};
Since GetRequest is used in various places, I can't utilize its success function directly within ShowData.
I'm looking for advice on how to ensure ShowData pauses its execution until GetRequest completes. One idea I had was modifying the OnSuccessCallBack function and tracking the initial function calling GetRequest(), but I'm unsure of the best approach.
Any suggestions or guidance would be greatly appreciated. Thank you.