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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:17:08+00:00 2026-05-26T06:17:08+00:00

Why won’t foo get appended? $.ajax({ type: ‘GET’, dataType: ‘json’, cache: false, url: ‘barfoochakalaka’,

  • 0

Why won’t foo get appended?

$.ajax({
                type: 'GET',
                dataType: 'json',
                cache: false,
                url: 'barfoochakalaka',
                success:
                    function(response) {
                        $.each(response, function(index, val) {                             
                            $(this).parent().parent().append('foo');
                        });

                    }
})
  • 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-05-26T06:17:09+00:00Added an answer on May 26, 2026 at 6:17 am

    Because inside each, this is set to the current element being iterated over (docs), so normally we define this to be something else before we enter the each loop:

    var that = this;
    $.each(response, function(index, val) {
        var content = '<div class="link-history">'+ val.date + ', ' + val.userid + ', ' + val.status + '</div>';
        $(that).parent().parent().append('foo');
    });
    

    However, in this circumstance, this in the success callback of an AJAX request is equal to the jqXHR object which launched the request, not the DOM element you’re after, so we have to move the var that = this to even further away;

    var that = this;
    $.ajax({
        type: 'GET',
        dataType: 'json',
        cache: false,
        url: 'barfoochakalaka',
        success: function(response) {
            $.each(response, function(index, val) {
                var content = '<div class="link-history">' + val.date + ', ' + val.userid + ', ' + val.status + '</div>';
                $(that).parent().parent().append('foo');
            });
    
        }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why won't this work in Safari? <script language=javascript type=text/javascript> function changeUrl(url) { window.location.href='http://google.com'; return
why won't this work? function login(){ if(window.XMLHttpRequest){ ajax=new XMLHttpRequest(); }else if(window.ActiveXObject){ ajax=new ActiveXObject(Microsoft.XMLHTTP); }
Mono won't fire the following code: I get internal server error 500, error writing
Why won't this template compile? template <class K, class V = Referenced> class Cache
I won't to write some values into database with ajax on submit event, after
Why won't it shuffle the array so I get a random result each time?
Why won't argparse parse these arguments? --foo 1 2 3 bar Using parser =
This won't work in Kohana 3.2 for some reason: $this->request->headers['Content-Type'] = 'text/xml'; Has this
Why won't my simple c++ code compile? get undeclared identifier errors. I can't see
Why won't my Telerik ComboBoxFor bind my value and fill my ComboBox via AJAX?

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.