jquery ajax plug in dynamic options

Posted on 2012-09-01
Last Modified: 2012-09-02
How can I make the attached snippets dynamic.

I need all of the name value pairs created in Snippet 1 to pass thru to Snippet 2 without revising Snippet 2.

I would like snippet 1 to be based on an array, something like

arrList = New Array("url", "destination", etc)
for(x = 0; x < arrList.length;x++)
    arrList[x] + ":" + $('#' + arrList[x]).val()

This would make the solution much more scalable.
Question by:KeithMcElroy

    Author Comment


    Author Comment

    one possibility:  use serialize() to formulate the vales in to name&value pairs.

    Author Comment

    is there a way to pass the contents of the variable ser to the ajax functon as a get?

          $(document).on('keypress','input', function(){
                var keycode = (event.keyCode ? event.keyCode : event.which);
                      if(keycode == '13'){
                      var ser = $('form').serialize();
                                  'url' : 'TSRIQBEF/jx/searchjx.asp',
                                  'destination' : '#searchtarg',
                                  'exectype' :  'search',
                                  'pe_id' :  $('#pe_id').val() ,
                                  'pe_name' : $('#pe_name').val() ,
                                  'pe_first' : $('#pe_first').val(),
                                  'pe_last' :  $('#pe_last').val(),
                                  'pe_middle' : $('#pe_middle').val(),
                                  'pe_url' : $('#pe_url').val()

    LVL 42

    Accepted Solution

    have you tried javascript objects?  then very easy to pass from one to the other


    var myobject = {
        myarray: [4,5,2,6,7,8],
        name: "michael",
        subobject: {
            id: "sub"

    Open in new window


    Author Comment

    So, sounds very good.  How would I pass the object into the ajax data?

    I guess the flow would be
    1.  create the object
    2.  pass the object into the ajax

    Author Comment

    the more I think about it, the more it makes sense to me to simply pass the serialized values so that they get picked up by the receiving ajax page which is an asp page



    Hope makes sense.
    LVL 42

    Expert Comment

    by:Rob Jurd, EE MVE
    yes that would make sense.  i was referring to passing the values between the two javascript functions.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    To Start with ... One of the most annoying things in developing web pages is handling the 'Enter Key' for form submission. The 'Enter Key' makes form submission so easy that the user always tend to use it. The easiest and the most intuitive way …
    Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now