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

  • Home
  • SEARCH
  • 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 9208719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:40:39+00:00 2026-06-18T00:40:39+00:00

As the title already mentions, is there a way to check whether a variable

  • 0

As the title already mentions, is there a way to check whether a variable is a real jqXHR?

I mean (imaginary):

var resource = $.get('/resource');

if (resource instanceof jqXHR)
{
    // do something
}

The actual problem I am trying to solve, is for a modal-plugin I’m working on.

$('#element').modal({
    content : function()
    {
        return $.get('/resource');
    }
});

And, the content variable can be either string or function. In case of string, it will be static, in case of function it will be run every time upon opening the modal.

But, I am looking to allow the content callback to return either jqXHR or string. With string it’s pretty simple, if (typeof returned === 'string'), but what about jqXHR?

I know that I could simply check for string and in case it’s not a string, assume it’s jqXHR, but I want my plugin to be as strong as possible, and disallow working with unexpected types.

  • 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-18T00:40:40+00:00Added an answer on June 18, 2026 at 12:40 am

    I suggest just checking whether or not it is a promise object. This will make your code more robust in that the user can return a custom deferred object if they need to do something more complex, or they can simply return the jqXHR for the same effect.

    if ($.type(resource) === "string") {
        doStuff(resource);
    } elseif (resource && resource.promise) {
        resource.promise().done(doStuff);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question is already been asked in title. Here is a code: (function($){ var filter
There are already several questions with a similar title, but they received either no
As the title already mentions do I want to change my ImageView onClick. I
the title already tells the question: you can successfully call the Print-Method on a
as the title already says, I want to execute a linux comand with a
as the title already says... I'd like to open a ElementTreeSelectionDialog with the Tree
The title is my question. I already found a topic related to this here
i need to retrieve the page title from an URL i already have using
Please don't confuse with the title as it was already asked by someone but
I just want what my title says.I have already read all the previous similar

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.