简体   繁体   English

jQuery .load()在本地工作,但不在服务器上工作

[英]Jquery .load() works locally but not on the server

I am not quite sure what is causing the issue here. 我不太确定是什么引起了这里的问题。 I am trying to load a view into a Jquery dialog using the .load() function. 我正在尝试使用.load()函数将视图加载到Jquery对话框中。 On my local machine everything works fine, but on the server the URL that ends up being created is not correct because it is adding the parameter to the URL twice. 在我的本地计算机上,一切正常,但是在服务器上,最终创建的URL不正确,因为它将参数两次添加到了URL。

The links are dynamic from a webgrid which is where the @item.GrouperIDForLookip comes from. 链接是来自@ item.GrouperIDForLookip所在的WebGrid的动态链接。

<div id="groupersDialog"></div>
<a id="GrouperField_@item.GrouperIDForLookup" class="grouper">Groupers</a>
...
<script>
    $(".grouper").on("click", function () {
        var id = $(this).attr("id").split("_")[1];
        $('#groupersDialog').dialog({
            autoOpen: true,
            width: 1000,
            height: 600,
            resizable: true,
            draggable: true,
            title: "Groupers",
            model: true,
            show: 'slide',
            closeText: 'x',
            dialogClass: 'alert',
            closeOnEscape: true,
            open: function () {
                //Load the Partial View Here using Controller and Action
                $('#groupersDialog').load('/Home/_Groupers/?GroupIDForLookup=' + id);
            },

            close: function () {
                $(this).dialog('close');
            }
        });
});
</script>

On my local machine everything works fine and the URL for the load works. 在我的本地计算机上,一切正常,并且加载的URL有效。 But on the server when running it the URL that ends up being created is %2fHome%2f_Groupers%2f%3fGroupIDForLookup%3d2&GroupIDForLookup=2 which doubles the GroupIDForLookup gives me a GET 404 (page not found). 但是在服务器上运行它时,最终创建的URL是%2fHome%2f_Groupers%2f%3fGroupIDForLookup%3d2&GroupIDForLookup=2 ,这使GroupIDForLookup翻了一番,这给了我GET 404(找不到页面)。

Does anyone happen to know what would cause this to happen? 有谁碰巧知道会导致这种情况发生的原因? If you need more code just let me know. 如果您需要更多代码,请告诉我。

Please update the URL in the load function in the below code. 请在以下代码中的加载功能中更新URL。

<div id="groupersDialog"></div>
<a id="GrouperField_@item.GrouperIDForLookup" class="grouper">Groupers</a>
...
<script>
    $(".grouper").on("click", function () {
        var id = $(this).attr("id").split("_")[1];
        $('#groupersDialog').dialog({
            autoOpen: true,
            width: 1000,
            height: 600,
            resizable: true,
            draggable: true,
            title: "Groupers",
            model: true,
            show: 'slide',
            closeText: 'x',
            dialogClass: 'alert',
            closeOnEscape: true,
            open: function () {
                //Load the Partial View Here using Controller and Action
                $('#groupersDialog').load(
                '@URL.Action("_Groupers", "Home")?GroupIDForLookup' + id);
            },

            close: function () {
                $(this).dialog('close');
            }
        });
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM