Copied to clipboard

Flag this post as spam?

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


  • sony 11 posts 111 karma points notactivated
    Jan 15, 2016 @ 07:11
    sony
    0

    What should be the URL in Ajax hit in user control?

    Hi Support,

    Please let me know What should be the URL in Ajax hit in user control?

    I am doing like this but not working .

    <script>
        $('.btn').click(function () {        
            $.ajax({
                url: "/usercontrols/ProductTemplate/test",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    var a = data;
                    alert("success");
                }, error: function () {
                    alert("error");
                }
            });
        });
    </script>

    Getting error. I think may be url parameter is wrong.

    UserControl and its code behind file is in usercontrol folder.

    Usercontrol name is : "ProductTemplate" and method is "test"

    Current verstion : 6.2.1

    Any help would be appriciated.

    Thanks.

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 15, 2016 @ 09:11
    Dan Lister
    1

    Hi Sony,

    I don't think you can directly call a UserControl by it's URL. You'll have to put the UserControl on a Web Page and call the Url of the page via your ajax request.

    Thanks, Dan.

  • Marc Goodson 2142 posts 14345 karma points MVP 8x c-trib
    Jan 15, 2016 @ 09:12
    Marc Goodson
    100

    Hi sony

    The UserControl won't have a direct Url that you can call it from clientside code and create a response.

    You could put the UserControl into a page template and publish that page, will give a Url to make the request to.

    Or you could create an UmbracoAPIController

    https://our.umbraco.org/documentation/reference/routing/webapi/

    which is designed to create an endpoint to make custom data available from Umbraco, ie to call from client side code.

Please Sign in or register to post replies

Write your reply to:

Draft