javascript - Get JSON from web service using jQuery -


so javascript looks like:

    try {         var response = $.ajax({             type: "get",             contenttype: "application/json; charset=utf-8",             url: "budgservice.asmx/loaddetail",             data: "{'building': '63170', 'currentyear':'2014'}",             datatype: "json"         });         $.when(response).then(function () {             loaddata();         });     } catch (err) {         alert(err);     }      function loaddata() {         alert('here');     } 

and web service

    [scriptmethod]     public string loaddetail(string building, string currentyear) {         return "[{color:\"red\", value: \"#f00\"}]";     } 

but never loaddata function , nothing gets populated response.

what missing?

your json invalid.

for response:

in javascript object literal syntax, property names may strings or identifiers, in json must strings.

"[{\"color\":\"red\", \"value\": \"#f00\"}]" 

for request:

in javascript, strings may delimited " or ' characters, in json must delimited " characters.

data: '{"building": "63170", "currentyear":"2014"}', 

as rule of thumb, better build native data structure , use json library serialise json instead of trying handcraft json.

also, can't include request body in request. need use post.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -