【问题标题】:Cannot post successfully if not using cassini for jQuery posts in ASP.NET MVC如果不使用 cassini 在 ASP.NET MVC 中发布 jQuery 帖子,则无法成功发布
【发布时间】:2009-04-27 15:47:40
【问题描述】:

当我将项目设置为使用 Visual Studio 开发服务器 (Cassini:Port) 启动应用程序时 我的 jQuery 正确发布到以下 URL

“SomeController/SomeMethod”。

当我使用 localhost 运行以下 URL 时,它不起作用

“http://localhost/Store/SomeController/SomeMethod”或 “SomeController/SomeMethod”。

有人遇到过这种问题吗?

【问题讨论】:

    标签: jquery asp.net-mvc post


    【解决方案1】:

    尝试使用 Url.Action 映射 URL,以便无论虚拟根是什么,它们都是正确的。

    $.post( '<%= Url.Action( "SomeMethod", "SomeController" ) %>'
            data,
            function() { ...callback.. },
            'json' );
    

    如果这仍然不起作用,那么我们可能需要查看您的路由设置。了解 ActionLinks 是否有效但 jQuery AJAX 无效也会很有帮助。如果是这种情况并且 URL 相同,那么您的 Javascript 文件可能没有正确的 url。在这种情况下,您需要使用 Url.Content 来映射这些 URL,以便它们始终正确。

    <script type="text/javascript"
           src='<%= Url.Content( "~/Scripts/jquery-1.3.2.js' ) %>'>
    </script>
    

    【讨论】:

      【解决方案2】:

      您可以在 iis yourapp.com 和 [WindoewsRoot]\System32\drivers\etc\host 添加行 127.0.0.1 yourapp.com 现在您可以在此 url http://yourapp.com/testpage/

      上测试您的应用程序

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-19
        • 1970-01-01
        • 2010-11-28
        • 1970-01-01
        • 1970-01-01
        • 2019-11-12
        • 1970-01-01
        相关资源
        最近更新 更多