1

I have the following ajax call. I want to send out the data in jason format. However I noticed in Fiddler that the data is converted to query string parameters. What I am doing wrong?

  $.ajax({
        type: "GET",
        url: "StatusService.svc/CheckStatus",
        data: JSON.stringify({"companyName":"paymins"}),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert('ok!');
            alter(data.toString());
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(textStatus + ' / ' + errorThrown);
        }
    });
2
  • 4
    Because you're doing a get request. Commented Nov 14, 2012 at 20:47
  • 1
    Note that dataType: "json" tells jQuery the expected format of the response, not the format of the request. Commented Nov 14, 2012 at 20:53

2 Answers 2

2

Change the type of your request to a post.

  $.ajax({
        type: "POST",
        url: "StatusService.svc/CheckStatus",
        data: JSON.stringify({"companyName":"paymins"}),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert('ok!');
            alter(data.toString());
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(textStatus + ' / ' + errorThrown);
        }
    });
Sign up to request clarification or add additional context in comments.

2 Comments

Try specifying your headers as updated. stackoverflow.com/questions/11492325/…
It's mine own WCF service configuration problem. Thanks all.
2

Get cannot contain a body. Use post for that.

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.