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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:33:50+00:00 2026-06-12T11:33:50+00:00

I have the following code: function submitHandler(dialog) { dialog.$submits.disableBt(); dialog.$message.addMessage(loading, <li>Contacting Server, please wait

  • 0

I have the following code:

function submitHandler(dialog) {

    dialog.$submits.disableBt();
    dialog.$message.addMessage("loading", "<li>Contacting Server, please wait ...</li>");
    $.ajax({
        url: href,
        dataType: 'json',
        type: 'POST',
        data: dialog.$form.serializeArray()
    })
        .done(onSubmitDone())
        .fail(onSubmitFail());
}

This function has a parameter of dialog which is an object looking like this:

{
        $modal: $modal,
        $form: $modal.find('.form'),
        $message: $modal.find('.message'),
        $submits: $modal.find('.submit-button'),
        href: $form.attr('data-href')
    };

I need to send the dialog object to the onSubmitDone and onSubmitFail functions. Previously I was not using an object
to hold $modal, $form etc and the variables were all available to all functions that were enclosed within an outer function

Two questions:

Is it sensible to pass things around as parts of an object or should I just declare these variables at the top of an outer function.

If I do pass around the object how can I pass it to the following:

function onSubmitDone(json) {
    json = json || {};
    if (json.Success) {
        switch (action) {

I understand that my json object is passed but how can I pass the dialog object also?

  • 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-12T11:33:51+00:00Added an answer on June 12, 2026 at 11:33 am

    If you pass your object as the context option of $.ajax, it will be available as this inside onSubmitDone and onSubmitFail:

    var jsonObj; // do you really need this global?
    
    function submitHandler(dialog) {
        jsonObj=dialog.$form.serializeArray();
        dialog.$submits.disableBt();
        dialog.$message.addMessage("loading", "<li>Contacting Server, please wait ...</li>");
        $.ajax({
            url: href,
            dataType: 'json',
            type: 'POST',
            data: jsonObj ,
            context: dialog
        })
            // Don't call the handlers from here, no ()!
            .done(onSubmitDone)
            .fail(onSubmitFail);
    }
    
    // Receives the data from the server
    function onSubmitDone(response) {
        // your object is available as 'this':
        console.log(this.$modal);
    }
    
    // Different params here, but 'this' is the same
    function onSubmitFail(jqXHR, textStatus) { /* ... */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: var submitHandler = function ($link, $form, close) { var
I have the following code function exibirDialog(div) { $(#divDialogo).ready(function() { $(#divDialogo).dialog({ open: function() {
I currently have the following code: function render(url1, url2, message) { utility.messageBoxOpen(message); $.getJSON(url1, function
I have the following code: function submitHandler($link, $modal, close) { var $form = $modal.find('#main-form');
I have the following code: var btns1 = { 'Submit': function (win) { submitHandler(oLink.$link,
I have the following code: function isValidAuthor($authorID){ $query = SELECT * FROM jos_users WHERE
I have the following code: function build_all_combinations(input_array){ array = [1,2,3] limit = array.length -
I have the following code: function Person(){ this.age = 30; } function Stats(){ this.age
I have the following code function generate_pdf() { $fdf_data_strings = $this->get_hash_for_pdf(); #$fdf_data_names = array('49a'
I have the following code: function toggleChecked(status) { $(.checkbox).each( function() { $(this).attr(checked,status); }) }

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.