Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to a JQuery $.getJSON callback method?

 function CallMethod() {      $.getJSON('/website/RESTfulService.svc/LiveLocation/json?{x=1,y=2}', function(data) {          getResult(data.lat, data.lon);      });  } 
like image 202
Abdallah Avatar asked Mar 05 '12 16:03

Abdallah


2 Answers

Pass them as an object just after the URL and before the function:

function CallMethod() {      $.getJSON('/website/RESTfulService.svc/LiveLocation/json',       {         x: "1",         y: "2"      },       function(data) {          getResult(data.lat, data.lon);      }); } 
like image 146
Zheileman Avatar answered Sep 24 '22 10:09

Zheileman


Alternatively, first create javascript object for the sake of simplicity and then pass

var myObject = {x: "1", y: "2"};  $.getJSON('/website/RESTfulService.svc/LiveLocation/json', myObject, function(dataVal) {     //Use Your result }); 
like image 37
Rahul Srivastava Avatar answered Sep 21 '22 10:09

Rahul Srivastava