0

I am calling a WebMethod() using $.ajax() and it doesn't seem like the VB is handling the data correctly.

Here is my JS:

$.ajax({
    type: "POST",
    url: "Default.aspx/RemoveUser",
    data: "{'s':'test'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        alert(msg.d);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        alert(textStatus + "\n" + errorThrown);
    }
});

And I created two RemoveUser functions, below:

<WebMethod()> _
Public Shared Function RemoveUser(ByVal s As String) As String
    Return s
End Function

and

<WebMethod()> _
Public Shared Function RemoveUser() As Boolean
    Return True
End Function

However, when I execute the above JS I get "true" returned. It is passing the data correctly:

POST data

Commenting out the RemoveUser(ByVal s As String) function does not change behavior at all.

2
  • 1
    I've been doing some googling...just wondering: Are you sure it's supposed to be "{'s':'test'}" ? It looks like it might need to be '{"s":"test"}' Commented Dec 12, 2012 at 18:38
  • @sacredfaith: No change when swapping the quotes; good idea, though. Commented Dec 12, 2012 at 20:08

2 Answers 2

1

I think you are using overloading methods here:

Check this out: .NET Overload WebMethods - Possible?

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

Comments

0

Get rid of the quotes, the data element can be an object. Currently you were passing nothing...
Try this:

data: {"s":"test"},

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.