Reputation: 1909
In JQuery if you want to pass a variable into ajax the code can be like this
$("#productselection").load("/productform", {product: $("#product").val()});
What's the right way to load more than one?
Upvotes: 0
Views: 1101
Reputation: 791
You can either create a new object and then pass it, or pass it straight way.
var data = {
'product': 'bar',
'product2': 'bar',
'product3': 'bar
}
$("#productselection").load("/productform", data);
You can aswell pass arrays of data
$( "#objectID" ).load( "test.php", { "products[]": [ "bar1", "bar", "bar3"] } );
Upvotes: 0
Reputation: 126
You can pass as many values as you want to that second argument:
$("#productselection").load("/productform", {
product: $("#product").val(),
another: 1234,
foo: "something else..."
});
Read .load()
documentation here: http://api.jquery.com/load/
Upvotes: 1
Reputation: 133453
You can pass JSON object like
$("#productselection").load("/productform", {
product: $("#product").val(),
product2: $("#product2").val(),
foo: "bar"
});
For more info visit official docs
Upvotes: 0