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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:43:09+00:00 2026-05-25T01:43:09+00:00

Okay I am working with some jquery creating dynamic popups. However, periodically the response

  • 0

Okay I am working with some jquery creating dynamic popups. However, periodically the response will be the name of a function that I need to call instead of actual data and I am trying to figure out how to do this..

success: function(response) {
                                var obj = $.parseJSON(response);
                                if (obj.response == 'false') {
                                    $('#popuperrDisplay').html(obj.msg);
                                    $('#popuperrors').show();
                                } else {
                                    if (obj.response == 'redirect') {
                                        window.location.href = obj.msg; 
                                    } else if (obj.response == 'function') {
                                        call obj
                                    } else {
                                        $(this).dialog('close');
                                    }
                                }
                            }

This is the current portion of my jquery. I need to figure out how I can send the name of a JS function through json_encode and have JS actually call 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-05-25T01:43:09+00:00Added an answer on May 25, 2026 at 1:43 am

    If the function is defined globally (on the window object), you could simply invoke it like so:

    if (obj.response === 'function' &&            // 1
        typeof window[obj.msg] !== 'undefined') { // 2
    
        window[obj.msg]();                        // 3
        // or...
        window[obj.msg].apply(null, obj.args);    // 4
    }
    
    1. checks whether the type of the response is a function.
    2. checks if there is a function with the given name defined on the window object.
    3. calls that function.
    4. calls that function and provides it with an array of arguments.

    Edit: (window[] syntax)

    To further clarify, window['showPopup'] accesses the showPopup member of the window object. It’s the same as doing window.showPopup. Only, the [] syntax has the advantage of receiving a string instead of actual code.

    window['showPopup'] will return an object (if defined); let it be a function for our particular example.

    We then call that function object by using the () operator, like so: window['showPopup'](). Once again, this is the same as doing this: window.showPopup().

    Edit 2: (invoke with arguments)

    If the function has to be invoked with an array of arguments, we can use apply. Invoking the function would then look like:

    window['showPopup'].apply(null, arrayOfArgs);
    

    Where arrayOfArgs is an array containing the arguments.

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

Sidebar

Related Questions

Okay I need help, again! For some reason it is not working, no idea
Okay, so I've created a custom template for Joomla, and gotten that working. However,
Okay I need some insight. I am taking a C++ class and am working
Okay! I really need your help or some tips I need a program that
I have some problems with ajax responses. Everything is working okay, however I got
Okay so im working on this php image upload system but for some reason
I'm working with a function which yields some data as a std::vector<char> and another
Ok been working with WPF for a while but I need some help. I
Okay so I made some changes in my project that resulted in a huge
Okay, so as part of the coursework I'm working on I've added some HTML5

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.