Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .load() with multiple variables

I am using the jquery .load() method for a search. I have figured out how to send one variable, but I need to send many.

WITH ONE

var field1 = ($('#form1 input[name="field1"]:text').val());
$('#results').load("/search/show.php", {field1: field1});

How would I do two variables? THIS WONT WORK

var field1 = ($('#form1 input[name="field1"]:text').val());
var field2 = ($('#form1 input[name="field2"]:text').val());
$('#results').load("/search/show.php", {field1: field1}{field2: field2});

I'm sure there is an easy way to send multiple variables, I just don't know how!

like image 545
livinzlife Avatar asked May 24 '11 02:05

livinzlife


1 Answers

You're looking for:

var field1 = ($('#form1 input[name="field1"]:text').val());
var field2 = ($('#form1 input[name="field2"]:text').val());
$('#results').load("/search/show.php", {field1: field1, field2: field2});

Check out object literals on the MDC.

like image 80
Andrew Whitaker Avatar answered Sep 22 '22 13:09

Andrew Whitaker