function CallMethod() {
$.getJSON('/website/RESTfulService.svc/LiveLocation/json?{x=1,y=2}', function(data) {
getResult(data.lat, data.lon);
});
}
Asked
Active
Viewed 8.7k times
39
-
try '/website/RESTfulService.svc/LiveLocation/json?x=1&y=2' – Nicocube Mar 05 '12 at 16:55
3 Answers
92
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);
});
}

Zheileman
- 2,509
- 20
- 23
-
1
-
How about passing no parameter/void? should I do `$.getJSON('/website/RESTfulService.svc/LiveLocation/json',null,function(data){...});`? – Dylan Czenski Sep 02 '16 at 22:17
11
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
});

Holger Ludvigsen
- 2,320
- 1
- 26
- 31

Rahul Srivastava
- 373
- 5
- 8
-
This is basically the same answer as Zheileman's, and it is not easy to read. – Holger Ludvigsen Sep 19 '17 at 07:25
-
I know this is the same answer but the way of passing your data as a parameter is different. I have already mentioned that It is for the sake of simplicity. – Rahul Srivastava Sep 19 '17 at 08:47
-
I see your point. I have submitted a suggested edit of your answer which is more readable (which is the purpose of this alternative solution) – Holger Ludvigsen Sep 19 '17 at 08:53
4
Just like Zheileman said, but note that this way, although you passed the parameters in JSON format, the actual parameters are passed to the webserver as an Encoded HTTP URL which will end up this way:
/website/RESTfulService.svc/LiveLocation/json?x=1&y=2

Tal Tikotzki
- 373
- 3
- 7