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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:38:50+00:00 2026-06-05T12:38:50+00:00

I have created a jQuery plugin that is used to create html on a

  • 0

I have created a jQuery plugin that is used to create html on a page with the xml that it reads from a webservice call. As a backup, if the webservice call fails, there is default xml stored in a var to use to build the html. Right now, the webservice is not available to me so I am stuck testing the failure scenario with dummy xml. I have everything written and working with the $.ajax call excluded, when I included the $.ajax call to the webservice in my code it still works fine, but chaining is broken.

I know to “return this;”, and I have implemented the $.when().then() wrapping my $.ajax call to take care of any problems that the asynchronous nature of an ajax call may introduce, but chaining still does not work. The firebug console always tells me that my method return is undefined when it gets to the next method in the chain, which leads me to believe I am not in fact returning “this” at all even though it looks to me like I am. My code is below (replaced a lot with pseudocode to save time):

(function( $ ) {

$.fn.createHtmlFromWS = function( options ) {

    var $this = $(this);

    //function to output the parsed xml as HTML appended to the jQuery object the plugin was called on
    function buildNav(dispXml){

        //logic to append xml to $this as custom html goes here

        return $this;
    }

    //fallback xml if webservice call fails
    var failXml = '<?xml version="1.0" encoding="utf-8"?><hello><world>earth</world></hello>';

    //dummy service url to force webservice fail scenario
    var serviceUrl = 'http://1234lkjasdf/test';

    //Note: this call that does not attempt $.ajax call to webservice WORKS with chaining
    //return buildNav($.parseXML(failXml));

    //call to webservice
    $.when($.ajax({
        type: 'GET',
        dataType: 'xml',
        url: serviceUrl,
        timeout: 10,
    })).then(function(a1) { //function to call if succeeded
        return buildNav($.parseXML(a1[2].responseXml));
    }, function(){ //function to call if failed
        console.log("in the error part of then"); //Note: this is output to log, I know i'm in the right spot

        //This line does not seem to be returning $then which is required for chaining, although it is building the html as expected
        return buildNav($.parseXML(failXml)); 
    }); 
};
}) ( jQuery );
  • 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-05T12:38:54+00:00Added an answer on June 5, 2026 at 12:38 pm

    This is due to the fact that you are returning from your callback functions, not the function itself. By the time your AJAX request has completed, your original function has long since returned undefined.

    Just after your AJAX call, and just before the end of the function, you’ll probably want to return $this;

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

Sidebar

Related Questions

I am using the jQuery Tools Scrollable plugin - http://flowplayer.org/tools/scrollable.html#navigator I have created a
I have created a jQuery elastic plugin. I have the problem that if I
I have used the jQuery Qtip plugin to create some tooltips using the following
I have created a jQuery plugin that works great with the exception of being
I have created a nice tooltip box using JQuery and I used some plugin
I have created a jQuery plugin that grabs a JSON feed (in this case
I have created a jquery plugin to expand/collapse ul,li something like a accordion menu
I have created some JQuery that will expand a div 'popup' on hover and
I have created a jQuery animation that can be seen by clicking the Preview
I have a page that uses Ryan Bates nested_form plugin . The plugin is

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.