Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:54:15+00:00 2026-06-15T16:54:15+00:00

I have a HTML page as shown in http://jsfiddle.net/Lijo/zPAfF/6/ . When searchReportButton button is

  • 0

I have a HTML page as shown in http://jsfiddle.net/Lijo/zPAfF/6/ . When “searchReportButton” button is clicked a javascript function “checkSession” is invoked. Inside the “checkSession” function there is a jquery.ajax call to a web method listed below. The web method is working fine and I am able to alert the result as “ACTIVE” in javascript success callback.

I have set the context as this.

 context: this,  //CONTEXT 

I am expecting the following code to alert the “Loading…” text. The assumption is this will work in the success callback since the context is set. But it not showing the text.

if (result == "ACTIVE") 
{       
    var selectedTable = $(this).closest('.dateFilter').siblings('.sentDatesSection').find('.reportSentDatesDiv');

    alert($(selectedTable).text());

}

QUESTION

What need to be corrected in order to get the context in the callback?

Web Method

    [WebMethod(CacheDuration = 0)]
    public static string CheckSessionExpiry(string empID)
    {

        return "ACTIVE";
    }

enter image description here

jQuery

$(document).ready(function() {
    var searchReportButton = $('.searchReportButton');
    searchReportButton.click(function() {
        var selectedTable = $(this).closest('.dateFilter').siblings('.sentDatesSection').find('.reportSentDatesDiv');
        alert($(selectedTable).text());
        checkSession();
        return false;
    });
});

function checkSession() {
    var empID = 101;
    alert('Function Reached');
    $.ajax({
        type: "POST",
        url: "Error.aspx/CheckSessionExpiry",
        data: '{"empID": "' + empID + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        context: this,
        //CONTEXT
        success: handleSessionResult
    });
}

function handleSessionResult(result) {
    if (result.hasOwnProperty("d")) {
        result = result.d
    }
    if (result == "ACTIVE") {
        var selectedTable = $(this).closest('.dateFilter').siblings('.sentDatesSection').find('.reportSentDatesDiv');
        alert($(selectedTable).text());
    }
}​

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title>Report List </title>

</head>
<body>
<form>

<div id="wrapper">
    <div id="container">
        <div id="centralContainer">
            <div id="mainContainer">
                <div id="contentHolderDiv" class="contentHolderDiv">
                    <div id="searchContainer" class="searchContainer">
                        <div id="entryValues" class="repeaterContainer">
                            <div class="repeaterTableBorder">
                                <div class="repeaterRecord">
                                    <div class="repeaterIdentifier">
                                        <div class="reportTitle">
                                            Daily Financial Transaction:
                                        </div>
                                    </div>

                                    <div class="viewLogTitle">
                                        <div class="viewLogText">
                                            View Report Log
                                        </div>
                                    </div>
                                    <div id="reportLog" class="reportLog">
                                        <div class="dateFilter">
                                            <div class="filterElements">
                                                <div class="filterContents">
                                                    <input type="submit" name="ctl00$detailContentPlaceholder$repReports$ctl00$btnSubmit"
                                                        value="Get Reports" id="detailContentPlaceholder_repReports_btnSubmit_0" class="searchReportButton" />
                                                </div>
                                            </div>
                                        </div>
                                        <div class="sentDatesSection">
                                            <div class="reportSentDatesDiv">
                                                <p>
                                                    Loading...</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clear">
                    </div>
                </div>
            </div>
            <div class="clear">
            </div>
        </div>
    </div>
</div>
</form>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.js"></script>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:54:16+00:00Added an answer on June 15, 2026 at 4:54 pm

    Pass this as argument to the checkSession function:

    checkSession(this);
    

    and then:

    function checkSession(context) {
        var empID = 101;
        alert('Function Reached');
        $.ajax({
            type: "POST",
            url: "Error.aspx/CheckSessionExpiry",
            data: JSON.stringify({ empID: empID }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            context: context,  //CONTEXT
            success: handleSessionResult
    
            }
        });
    }
    

    Also notice how I have fixed your $.ajax call to use the JSON.stringify method in order to ensure that the request is properly JSON formatted. Never, and I repeat, absolutely never use string concatenations (+ operator) to build JSON. The JSON.stringify method is natively built into all modern browsers. And if you have to support some browser that comes from the Mesozoic era such as IE6 or something you could reference the json2.js script to your page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code as shown in http://jsfiddle.net/Lijo/PJcZQ/ . It has tow divs with similar
Website test page: http://www.lantiis.com/indexold.html jsFiddle: http://jsfiddle.net/Guhb4/7/ I received help with the jQuery and it
I have an html page with a link like this: <a href=javascript:window.print()>Print QR code</a>
Jsfiddle: http://jsfiddle.net/87YGW/ At present I have to click tab 1 to show content however
On my html page, there is a button which initially have the class name
I have a html page with a basic tab control. I use javascript to
I have a task to show digital clock (with minutes precision) on HTML page
I want to show three XMLs on a single html page. These XMLs have
I have a web page with a read-only text box which shows some HTML
I have HTML page where windows media player is embedded. It works very well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.