0

So my 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 I never get to the loadData function and nothing gets populated into response.

What am I missing?

1
  • 1
    What do you get when you visit BudgService.asmx/LoadDetail directly in the browser ? Commented Mar 24, 2014 at 20:37

1 Answer 1

1

Your JSON is invalid.

For your response:

In JavaScript object literal syntax, property names may be strings or identifiers, but in JSON they must be strings.

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

For your request:

In JavaScript, strings may be delimited with " or ' characters, but in JSON they must be delimited with " characters.

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

As a rule of thumb, it is better to build a native data structure and then use a JSON library to serialise it to JSON instead of trying to handcraft JSON.

Also, you can't include a request body in a GET request. You need to use POST.

Sign up to request clarification or add additional context in comments.

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.