Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

JQuery - $.get

Anyone give a link or basic example using the JQuery $.get function that includes more than one parameter taken from a field on the page.

What's the difference between that and $.ajax?
0
carsRST
Asked:
carsRST
  • 4
  • 3
  • 2
2 Solutions
 
effxCommented:
$.get(url, {param1:"test1", param2:"test2"}, function(data){
alert(data);
});
0
 
carsRSTAuthor Commented:
Can i replace the parameters with fields on the page?  

Something like this...

$.get(url, {ID: $("#ID").val(), name:$("#name").val()}, function(data){
alert(data);
});
0
 
leakim971PluritechnicianCommented:
var url = "path/to/page?param1=" + param1 + "&param2=" + param2;
var callback = function() { alert("well done!"); }
$.get(url, callback);

if all the parameters come from fields you may use : http://api.jquery.com/serialize/

var url = "path/to/page";
var callback = function() { alert("well done!"); }
$.get(url, $("form").serialize(), callback);

$.get is shorter than $.ajax isn't it?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
effxCommented:
More specifically:  
<input type="text" name="fieldTest1" />
<input type="text" name="fieldTest2" />
<input type="text" name="fieldTest3" />
<script>
var getURL = "";
$.get(getURL, {fieldTest1:$("input[name=fieldTest1]").val(), fieldTest2:$("input[name=fieldTest2]").val(), fieldTest3:$("input[name=fieldTest3]").val()}, function(data){
	alert(data);
});
</script>

Open in new window

0
 
leakim971PluritechnicianCommented:
if all the parameters come from fields in a form you may use : http://api.jquery.com/serialize/
0
 
carsRSTAuthor Commented:
effx,

$("input[name=fieldTest1]").val()

$("#fieldTest1").val()

Will either syntax work?  or is yours specific in this aspect?



leakim,
>>if all the parameters come from fields in a form

It's not a form, but rather just inputs on a page.
0
 
effxCommented:
Either one will work
0
 
carsRSTAuthor Commented:
well, i guess i would like to refer to by "ID" as opposed to name.
0
 
carsRSTAuthor Commented:
Thank you both!

Learned quite a bit in a short time.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now