Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take path from application root in javascript [duplicate]

function detailed_link(cell_rowid) {
        var $tabs = $('#infrTab').tabs();
        $tabs.tabs('select', 1); // switch to third tab~
        objRowData = $('#' + pageGridId).getRowData(cell_rowid);
        //document.getElementById("Name").value = objRowData.amount;

        loadPage('Infringement/TaskDetail', 'taskDetails'); /* Path */
    }

I have write a javascript function loadPage(), that needs a path to some page as a parameter. I need to give this path from the application root. I dont want a relative path. Please let me know how can I do it.

like image 534
Vaibhav Jain Avatar asked Sep 07 '10 04:09

Vaibhav Jain


1 Answers

I have this piece of Javascript in my Site.master, just underneath the jquery import and above any reference to my own scripts.

 <script type="text/javascript">
        //Function that provides a relative URL for cases of virtual directories.
        jQuery.url = function (path) {
            return '<%: Url.Action("Index","Home") %>' + path;
        };
 </script>

This assumes that your '/' address is handled by your Index method in your Home controller (the standard).

You can then access it via:

$.url('Infringement/TaskDetail')
like image 90
Alastair Pitts Avatar answered Oct 16 '22 09:10

Alastair Pitts