40
 function CallMethod() {
     $.getJSON('/website/RESTfulService.svc/LiveLocation/json?{x=1,y=2}', function(data) {
         getResult(data.lat, data.lon);
     });
 }
1
  • try '/website/RESTfulService.svc/LiveLocation/json?x=1&y=2' Commented Mar 5, 2012 at 16:55

3 Answers 3

94

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);
     });
}
Sign up to request clarification or add additional context in comments.

2 Comments

I had no idea this is possible, just great.
How about passing no parameter/void? should I do $.getJSON('/website/RESTfulService.svc/LiveLocation/json',null,function(data){...});?
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
});

3 Comments

This is basically the same answer as Zheileman's, and it is not easy to read.
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.
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)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.