locked
Url with Resolve Url RRS feed

  • Question

  • User-1499457942 posted

    H

     How to replace below line

    url: "/WebService.asmx/GetData"

    with ResolveUrl

    Thanks

    Sunday, July 29, 2018 10:09 AM

All replies

  • User475983607 posted

    Use code blocks.

    url: "<%=ResolveUrl("/WebService.asmx/GetData") %>",

    Keep in mind the snippet of code above must exist in an ASPX page and not a JS file.  JS files are static and not part of the page life cycle.

    Sunday, July 29, 2018 12:32 PM
  • User-1171043462 posted

    Use ~ sign so that ASP.Net will get the correct path with ResolveUrl

    url: '<%=ResolveUrl("~/WebService.asmx/GetData") %>',

    Sunday, July 29, 2018 12:48 PM
  • User-1171043462 posted

    And if you want to use in JS also then do this way

    in ASPX create a variable

    <script>
    var GetDataUrl = '<%=ResolveUrl("~/WebService.asmx/GetData") %>';
    </script>

    And then in JS use

    url: GetDataUrl,

    Sunday, July 29, 2018 12:50 PM
  • User-1499457942 posted

    Hi

      I have defined like this but it is saying GetDataUrl is not defined

    $(document).ready(function () {
    var GetDataUrl = '<%=ResolveUrl("~/WebService.asmx/GetData") %>';
    });

    function loadData()
    {
    $.ajax({
    type: "POST",
    dataType: "json",
    url: GetDataUrl,
    success: function (data) {
    var dt = $('#studentTable').DataTable({
    columnDefs: [{ orderable: false, targets: [2] }],
    //columnDefs: [{ visible: false, targets: [0] }],
    emptyrecords: 'No records to display',
    data: data,
    columns: [
    { 'data': 'No' },
    { 'data': 'Description' },
    {
    "mRender": function (data, type, row) {
    debugger
    return '<a class="btn btn-warning" onClick="getbyID(' + row.Id + ')" href="#">Edit</a>';
    }
    }]
    });

    }
    });
    }

    Thanks

    Sunday, July 29, 2018 1:19 PM
  • User-1171043462 posted

    $(document).ready(function () {
    var GetDataUrl = '<%=ResolveUrl("~/WebService.asmx/GetData") %>';
    });

    Just use

    var GetDataUrl = '<%=ResolveUrl("~/WebService.asmx/GetData") %>';

    Sunday, July 29, 2018 1:38 PM
  • User-1499457942 posted

    Hi

     U mean to say outside $(document).ready(function () { . I tried that also but not working

    Thanks

    Sunday, July 29, 2018 2:12 PM
  • User475983607 posted

     U mean to say outside $(document).ready(function () { . I tried that also but not working

    Is there anyway that you can explain clearly what you are trying to do and post all the relevant source code?  Phrases like "not working" is not specific enough to guess or reproduce your exact scenario.  

    Sunday, July 29, 2018 2:42 PM
  • User-1171043462 posted

    YES.

    Please share full code

    Sunday, July 29, 2018 2:52 PM
  • User-1499457942 posted

    Hi

    var GetDataUrl = '<%=ResolveUrl("~/WebService.asmx/GetAllCategories") %>';

    $(document).ready(function () {
        
        loadData();
    });  
    
    function loadData()
    {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: GetDataUrl,
            success: function (data) {
                var dt = $('#studentTable').DataTable({
                    columnDefs: [{ orderable: false, targets: [2] }],
                    //columnDefs: [{ visible: false, targets: [0] }],
                    emptyrecords: 'No records to display',
                    data: data,
                    columns: [
                        { 'data': 'No' },
                        { 'data': 'Description' },
                        {
                            "mRender": function (data, type, row) {
                                debugger
                                return '<a class="btn btn-warning" onClick="getbyID(' + row.Id + ')" href="#">Edit</a>';
                            }
                        }]
                });
    
            }
        });
    }

    Thanks

    Sunday, July 29, 2018 3:01 PM
  • User-1171043462 posted

    Put

    var GetDataUrl = '<%=ResolveUrl("~/WebService.asmx/GetAllCategories") %>';

    above

    function loadData()

    Sunday, July 29, 2018 3:30 PM