K20GH
K20GH

Reputation: 6281

Passing 2 sets of data using JQuery .Ajax?

I have a search box:

<input class="box" name="search" type="text" id="search_input" />

And a json_encode array called $findall. Using jQuery $.ajax() I want to be able to pass the array AND the "keyword" from the input via the data field. The code below has set the keyword from the search_input as the variable dataString

$.ajax({
                type: "GET",
                url: "core/functions/searchdata.php",
                data: dataString,  
        //data:{availableDevicesArray : availableDevices },
                beforeSend: function() {
                    $('input#search_input').addClass('loading');
                },
                success: function(server_response) {
                    $('#searchresultdata').append(server_response);
                    $('span#category_title').html(search_input);
                }

I can pass either dataString or the array, but not both which I need. How is it possible to pass them both?

UPDATE:

My PHP to get the array is:

mysql_select_db($database_database_connection, $database_connection);
$query = "SELECT * FROM Device_tbl";
$result=mysql_query($query, $database_connection) or die(mysql_error());
$findall = array ();
while($row = mysql_fetch_array($result)){

    $findall[] = $row;
}

and I am storing the availbleDevices array like so:

var availableDevices = <? echo json_encode($findall); ?>;

Upvotes: 0

Views: 158

Answers (1)

shadyyx
shadyyx

Reputation: 16055

You can create an object and push these variables as its properties:

data: {
    'string' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    'array' : [ 'one', 'two', 'three' ]
}

Upvotes: 2

Related Questions