2

I am getting the facebook data of the user using the facebook api as follow:

 function testAPI() {
            FB.api('/me?fields=id,name, birthday, picture.width(100).height(100), email', function (response) {
                if (response && !response.error)
                    //console.log(response);
                    buildProfile(response);
            })
        }

Now I want to pass the response json object to a method in c# as parameter. For doing that I am using the ajax as follows:

function buildProfile(user) {
            $.ajax({
                url: 'callback.aspx/SaveData',
                data: JSON.stringify(user),
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                }
            });
        }

There is method with name SaveData in c#, I have setup a breakpoint on that method.

The url: 'callback.aspx/SaveData' defined above should I have called the callback.aspx page in which SaveData method is present. But somehow I am not able to redirect to the page callback.aspx and to method SaveData in c#.

 public void SaveData(List<string> strings)
 {
            string text = "";
 }

Any help will be greatly appreciated. Thanks in advance.

9
  • Please post the details of that C# Controller Method you are referring to Commented Jul 13, 2018 at 9:57
  • "But somehow it is not working." What does that mean? An exeption? Unexpected behaviour? Commented Jul 13, 2018 at 9:59
  • 2
    If you don't post the not working method how can we help you? Commented Jul 13, 2018 at 9:59
  • I think you'd need your controller to accept a CLASS which matches the user object in terms of fields available, and not Json.stringify the data - just pass the user object as-is. Then it should work. At the moment MVC is probably trying to find an Action that expects a single string param and failing, so it's not calling the action on the controller. Commented Jul 13, 2018 at 10:01
  • 1
    Please share your C# method. Are you using Webform or mvc or web service? Commented Jul 13, 2018 at 10:05

1 Answer 1

1
[WebMethod]
public void SaveData(List<string> strings)
{
      string text = "";
}

The specific method being called needs an attribute WebMethod to be defined to be called using an ajax, I don't see the attribute in your case.

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.