0

I have an associative array and I'm trying to pass it to the parameters section of the jquery load method. However it is not showing up as a post on the server side. How can I accomplish this?

Here is my code:

var selectcustomerpopup = null;

$(document).ready(function() {
    // Find customer
    $('.CustomerSelectBtn').click(function() {
        var uniqueid = $(this).attr('id');

        var customerSelectURL = $('#ajax_customer_select_url').val() 
                   + "/" + uniqueid;
        var custselectdata = new Array();

        custselectdata["fname"] = "TestFirst";
        custselectdata["lname"] = "TestLast";

        if (! ($('#selectCustomerDialog').length)) {
          $('body').append(
              $('<div id="selectCustomerDialog" style="display: none;"></div>')
               );
        }

        var $findCustomerDialog = 
              $('#selectCustomerDialog').load
               (customerSelectURL, custselectdata)
            .dialog({
            autoOpen: false,
            title: 'Select Customer',
            width: 630,
            height: 450,
            position: 'center', 
            resizeable: true,
            modal: true,
            draggable: true,
            closeOnEscape: true,
            closeText: 'close'

        });
        $findCustomerDialog.dialog('open');
        selectcustomerpopup = $findCustomerDialog;
        return false;
    });
  } );

Additional Info: I got a good answer, but I did some more research and found a great link explaining associative arrays in javascript very well: http://blog.xkoder.com/2008/07/10/javascript-associative-arrays-demystified/

2
  • I think you need only to replace the custselectdata array with an object: var custselectdata = {}; Commented Oct 11, 2011 at 14:11
  • mblase, you had the correct answer, replacing the array with {} to make it an object was the solution that worked, but there is no answer for me to select. Commented Oct 11, 2011 at 15:22

3 Answers 3

1

JavaScript doesn't have true associative arrays. You only need to replace the custselectdata array with an object: var custselectdata = {};

Sign up to request clarification or add additional context in comments.

2 Comments

it might not be considered a true associative array, but it looks and acts like an associative array to me. If I can just figure out how to loop though the elements, I'll have everything I need.
@stephenbayer Yes, this is true. I just meant that you can't declare it as an array; you need to declare an object which then behaves exactly like an associative array. Looping through it can then be done using for (key in object) {...} and values can be obtained with something like var val = object[key];
0

The data needs to be formatted as a string:

http://api.jquery.com/load/

So you could do:

var custSelectData = "fname=TestFirst&lname=TestLast";

1 Comment

It doesn't need to be a string. A map of the data would work as well.
0

You can replace the custselectdata var for

var custselectdata = {fname: 'testfirst', lname: 'testlast'};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.