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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:44:17+00:00 2026-06-14T17:44:17+00:00

When inside a function can I get it’s parameters name/value? I’m looking to turn

  • 0

When inside a function can I get it’s parameters name/value?

I’m looking to turn those into an object that I can JSON.stringify() so I can pass it as data to an ajax call.

[EDIT]
Thanks to others pointing me in the right direction I have a solution that dynamically creates parameters that match the webmethod with a client stub that matches the webmethod as well. This, I think, helps make things more readable.

[EDIT2]
Took it a step further. Now the function name in javascript must match the name of the webmethod, and now you pass to it as the first param the page the webmethod exists on. It dynamically takes the client javascript function name, and that’s what it’s looking for now for the webmethod.

Here are the common methods that you create somewhere in your code:

    function WebMethodCall(args) {
        // in your stubs call this to get argname/value pairings in JSON form
        var params = JSONArgs(args);
        var fun = GetFunctionName(args);

        // make a call to the webmethod via ajax using json
        AjaxPostJSON(args[0] + "/" + fun, params, args);
    }

function JSONArgs(args) {
        var tmp = args.callee.toString().match(/\(.*?\)/)[0];
        var argumentNames = tmp.replace(/[()\s]/g, '').split(',');

        var param = new Object();
        for (var i = 0; i < argumentNames.length; i++) {
            param[argumentNames[i]] = args[i];
        }

        return JSON.stringify(param);
    }

    function GetFunctionName(args) {
        var fName = args.callee.toString().match(/function ([^\(]+)/)[1]

        return fName;
    }


    function AjaxPostJSON(url, data, args) {
        var objGetData = new Object();
        var fun = GetFunctionName(args);
        var s = "On" + fun + "Success";
        var f = "On" + fun + "Failure";

        objGetData.url = url;
        objGetData.type = "POST";
        objGetData.data = data;
        objGetData.contentType = "application/json; charset=utf-8";
        objGetData.dataType = "json";
        objGetData.success = window[s];
        objGetData.error = window[f];

        $.ajax(objGetData);
    }

The stub where the parameter names should match the webmethod parameter names. The function name MUST also match the webmethod function name. Note that page is required to be the first parameter, but shouldn’t be in your webmethod. It’s simply used here to make the call correct:
// function stub
function GetData(page, id, name) {
WebMethodCall(arguments);
}

Notice the success and failure name patter of “On” + func_name + “Success”/”Failure”. The usage:

    function Button2_onclick() {
        // call client side stub that matches the webmethod
        GetData("Default.aspx", 8, "Bob");
    }

    // automatically registers these as success/error
    function OnGetDataSuccess(data) {
        alert(data.d);
    }

    function OnGetDataFailure(data) {
        alert("failure");
    }

The nice thing about this, I think, is that when I change/add parameters to my webmethod, it’s so easy to just get the client javascript method and change the parameter names to match the webmethod and that’s it.

  • 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-14T17:44:19+00:00Added an answer on June 14, 2026 at 5:44 pm

    Does this help?:

    function test (name, pass){
        var params = (test.toString().substring(test.toString().indexOf('(')+ 1, test.toString().indexOf(')'))).replace(/ /g, '').split(',');
        var obj = new Object();
        var js = "";
    for(var i=0;i<arguments.length;i++){
            js += 'obj.'+ params[i]+' = "'+ arguments[i]+'";';
        }
         eval(js);
         JSON.stringify(obj);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I get the name of function inside a JavaScript function?
Can I get the name of all the function inside a package. Suppose I
How can I get all the function arguments in javascript inside an array? function(a,
Can someone explain to me why I cannot use document.getElementById('id').value inside of a function?
I don't think that I can use ORDER BY clause inside the GROUP_CONCAT function.
I would like to ask how can we get a value of a function
If doing console.log(data) from inside a function that get passed the result of an
How can I call a function from inside the function, so it becomes recursive?
I need to use a function inside of another function, how can I do
Can anyone tell me how I close an opened SQL connection inside a Function?

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.