I need to verify if a user is logged in using JavaScript when a button is clicked.
While I am aware that ajax can accomplish this task, I am unsure of where to begin and do not wish to delve into learning the entire ajax process.
Is there a straightforward code snippet that I could use as a reference?
==============================UPDATE 2===================================
After posting another question on this topic, I received an answer that might be helpful for others facing the same issue:
Can I return true to asp.net OnClientClick After an Ajax call? Or maybe some other way?
==============================UPDATE=====================================
Despite reading various examples, I have yet to find the specific one that I require. After receiving the server-side result, I am at a standstill. Below is my code - any assistance with the queries in the comments would be greatly appreciated. Thank you!
in .ascx:
<asp:Button ID="buttonSubmit" Text="Submit" OnClientClick="return buttonSubmitOnclick()" OnClick="buttonSubmit_Click" runat="server"/>
in .js:
function buttonSubmitOnclick() {
showLogin();
//What should I do here??? How do I return true if the ajax call returns 'true'?
return true; //???
}
//========== Ajax ==============
function showLogin() {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText == "false") {
$find('modalPopupLogin').show(); //Show Login Dialog
};
}
}
xmlhttp.open("GET", "AjaxService.aspx?t=auth", true); //??? should the last parameter be "false"???
xmlhttp.send();
}