0

I have passed a token from a View to a function in my HomeController, and now want to perform an action on the token and return the information to the frontend. I thought that the resultData from the ajax call would be the output of GetMyData, however it is just the token that I passed in in the first place. Any help would be great, thanks.

JS

$.ajax({
    url: '/Home/GetMyData',
    type: 'POST',
    dataType: 'json',
    data: {token: token},
    success: function(resultData){
        console.log(resultData);
    }
})

Home Controller

public JsonResult GetMyData(string token)
{
    ...
    return Json('ok')
}
1
  • 1
    It does when I test. Commented Apr 9, 2021 at 21:43

1 Answer 1

1

This works fine for me. Post more details if it's not working for you.

MVC

public JsonResult GetMyData(string token)
        {
            return Json("some result info");
        }

Script

<script>
    function getData()
    {
        let token = "test";
        $.ajax({
            url: '/Home/GetMyData',
            type: 'POST',
            dataType: 'json',
            data: { token: token },
            success: function (resultData) {
                console.log(resultData);
            }
        })
    }
</script>

enter image description here

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

1 Comment

Yeah it is working now actually after I restarted my server. Thanks!

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.