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 8544379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:35+00:00 2026-06-11T12:32:35+00:00

I have an old code which is dependant on JQuery 1.3.2 that uses the

  • 0

I have an old code which is dependant on JQuery 1.3.2 that uses the following ajax call

function ChangeContent(url, somepageobject) {
   var xhrobj = $.ajax({
       url: url,
       context: somepageobject,
       callback: doFurtherStuff,
       success: function(data) {
                somepageobject.html($(data));
                this.callback.call(this.context[0], data, "ok"); // >> Code breaks here
           }
  });
  return xhrobj;
 }

Problem with the code above is that this.callback is null when I upgraded to JQuery 1.8.1, most importantly the ChangeContent function is being used in different places and is outside my control (its used as as an API for external users…etc). An example of the usage of the above is like this:

xhr_object = ChangeContent("/someurl, $("#resultContainer"));

function doFurtherStuff(responseText, statusText, XMLHttpRequest) 
{
   var identifier = '#' + this.id;
   ...
}

Notice that the doFurtherStuff must have the correct “this” object value which is the context specified in ChangeContent function. When I tried to use different deferred then() …etc. functions in JQuery 1.8.1 to solve the above this.callback.call(this.context[0], data); problem after the upgrade the “this” object in the callback function had different value since I guess the new JQuery library handles that differently.

Is there anyway to fix the error above while limiting the change to ChangeContent function only as I try to avoid asking all users to change the way they call and handle call backs from that function?

  • 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-11T12:32:37+00:00Added an answer on June 11, 2026 at 12:32 pm

    When you add the context option, you are telling jQuery what this should be inside of the success callbacks. That means you can’t access the options passed into the ajax request. Either don’t supply a context, or pass in the callback manually.

    function ChangeContent(url, somepageobject) {
       var callback = doFurtherStuff;
       var xhrobj = $.ajax({
           url: url,
           context: somepageobject,
           success: function(data) {
                    somepageobject.html($(data));
                    callback.call(this[0], data, "ok"); // >> Code breaks here
               }
      });
      return xhrobj;
    }
    

    Update:
    If you want to instead continue using your code as-is, simply rename the context property.

    function ChangeContent(url, somepageobject) {
       var xhrobj = $.ajax({
           url: url,
           thecontext: somepageobject,
           callback: doFurtherStuff,
           success: function(data) {
                    somepageobject.html($(data));
                    this.callback.call(this.thecontext[0], data, "ok"); // >> Code breaks here
               }
      });
      return xhrobj;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have old code that uses size_t which IIRC comes from cstring.h. On OS
I have some old code that uses qsort to sort an MFC CArray of
We have some code kicking around that uses this old internal Sun package for
HI i have an old code which uses a scrapref and selects scrap using
I have a bunch of old C code, which I compiled using MinGW, and
I have some old code (an old but still maintained VB6 application) that from
I have a piece of old code that used a query using WQL to
I have a templating system that looks similar to old-style ASP code. I run
I am updating some old code and I have a subclassed UIView (GraphView) that
I've got some very old code which uses a Box to list some information.

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.