Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas 34 posts 114 karma points
    May 07, 2019 @ 09:50
    Thomas
    0

    Call Surface controller from ajax call

    Hi,

    I just tried to access umbraco surface controller from jquery ajax call. But its not fired, any one please let me know how to call umbraco surface controller via ajax

    eg: i have controller called EmployeeSurfaceController, in this i need to invoke getEmployees action method.

    Regards, Thomas

  • Jonathan Distenfeld 105 posts 618 karma points
    May 07, 2019 @ 10:37
    Jonathan Distenfeld
    0

    Hi Thomas,

    this would be an example ajax call:

    $.ajax(
    {
       url: "www.yourdomain.com/umbraco/surface/employeesurface/getemployees",
       data: yourData,
       type: "GET",
       success: function(data)
       {
          alert("success!");
          // do something with your data
       },
       error: function()
       {
          alert("something went wrong...");
       }
    });
    

    For more information:

    https://www.w3schools.com/jquery/ajax_ajax.asp

    https://our.umbraco.com/documentation/reference/routing/surface-controllers

    Jonathan

  • Bryna 73 posts 239 karma points
    May 08, 2019 @ 18:57
    Bryna
    0

    If your surface controller is inheriting from UmbracoAuthorizedJsonController, you will not be able to call it using ajax unless you are logged in[or pass credentials]. If you are able to post your surface controller class, it would help in narrowing down the issue.

  • Damien Holley 179 posts 540 karma points
    May 08, 2019 @ 21:53
    Damien Holley
    0

    I have used ajax previously to get data from a surfacecontroller.

    is employeesurface == employeesurfacecontroller in your namespace? Can you post your controller code or an example please?

    Also make sure the function getemployees is public with [HttpGet] access.

Please Sign in or register to post replies

Write your reply to:

Draft