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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:29:09+00:00 2026-05-12T08:29:09+00:00

Thank you all ahead of time. This is my first time developing a jQuery

  • 0

Thank you all ahead of time. This is my first time developing a jQuery plugin (and first time developing in javascript as well actually), and I have to say I’m pretty geeked (It probably has many hideous things to you seasoned js/jquery developers, but this is my first attempt – please bear with me :). I welcome any constructive criticism of any of the code too.

This is a model box plugin (yes, there are others, but job requirements dictate that I code my own to avoid third-party dependency) that displays text given, text from an ajax call, or a form given/taken from an ajax call and then handles the form submission via ajax. This needs to be as customizable as possible, so I am attemping to provide some hooks ( ?? – anonymous functions ) the user can use to pass custom code to the plugin.

The problem I am having is providing parameters to the user function. If I use the keyword ‘this’, I can pass the ‘msg’ variable fine and the user function can use it. But when I pass ‘msg’ instead of ‘this’ the user gets a blank variable. I would like to pass more than just the msg – also an array of data passed in the ajax call and a jQuery object of the model box is what I would really like to do.

Below is the snippet – the function is inside of and called within the plugin; I just grouped some code into functions for organization/development purposes.

    // Submits the form inside of the model box
    // and calls the user hooks of onFormSuccess and
    // onFormFailure for ajax success and error
    function submitForm() {
        var URL = $('form',$contentNode).attr('action'), 
        method = $('form',$contentNode).attr('method'),
        data = $('form',$contentNode).formSerialize();

        $.ajax({
            url: URL,
            type: method,
            data: data,
            success: function(msg) {
                // Doesn't work, but I would like it too
                //settings.onFormSuccess.call(msg, breakData(data) );
                // Does work
                settings.onFormSuccess.call(this);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                setings.onFormFailure.call(errorThrown);
            }
        });
        closeModel();
    }
  • 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-12T08:29:10+00:00Added an answer on May 12, 2026 at 8:29 am

    See the call syntax. The first parameter determines what this will be inside the callback function itself. It is not passed as a parameter to the callback function.

    To pass parameters to the callback you use the remaining parameters of call:

    settings.onFormSuccess.call(thisArg, msg, dataArray);
    

    The callback will then receive two parameters, and run with this pointing to thisArg:

    function successHandler(msg, dataArray) {}
    

    Another issue with your code is the value of this inside your success handler is meaningless. From what it looks like it will just point to the window object. So the callbacks you call will also be running with this == window.

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

Sidebar

Related Questions

Thank you one and all ahead of time. I am currently in the process
First of all thank you for your time and sorry if some issues are
First, I would to thank everyone for all the help they provide via this
This has to be a common question that all programmers have from time to
Thank you all for helping. Below this post I put the corrected version's of
EDIT: I have fixed all but two warnings now, so thank you all for
I apologize ahead of time if I am not asking this properly.. it is
Thank you all for your help. A number of you posted (as I should
What is the SQL query to select all of the MSSQL Server's logins? Thank
I recently asked this question: Expose XML or Objects - thanks all for the

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.