【问题标题】:How to do a 'HTTP-POST' with HyperlinkButton如何使用 HyperlinkBut​​ton 执行“HTTP-POST”
【发布时间】:2013-01-14 09:26:14
【问题描述】:

我有一个 silverlight 应用程序,用户可以在应用程序中输入 SQL 查询,然后服务器将查询结果作为 Excel 文件返回。

用户单击一个下载链接,该链接链接到服务器中的 HttpHandler,该 HttpHandler 生成 excel 文件。经过一些研究[1],我发现使用 HyperlinkBut​​ton 控件是提供文件链接的最可靠方法,而无需浏览器弹出安全设置的麻烦。

我需要将可能很长的 SQL 查询作为参数发送给 HttpHandler。 由于大小限制,我无法将其作为查询字符串(HTTP GET)包含在 url 中。

有没有办法使用 HyperlinkBut​​ton 进行“HTTP-POST”?

[1]Browser.HtmlPage.Window.Navigate is blocked but HyperlinkButton isn't - why?

【问题讨论】:

    标签: silverlight download http-post silverlight-5.0 httphandler


    【解决方案1】:

    在这种情况下,我认为您可以尝试使用 jquery 发送 get/post 请求。

    发布请求 API 文档:http://api.jquery.com/jQuery.post/

    获取请求 API 文档:http://api.jquery.com/jQuery.get/

    <!DOCTYPE html>
    <html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
    </script>
    <script>
    function f(){
        $.post("http://www.w3schools.com/jquery/demo_test_post.asp",
        {
          name:"Donald Duck",
          city:"Duckburg"
        },
        function(data,status){
          alert("Data: " + data + "\nStatus: " + status);
        }
    )};
    
    </script>
    </head>
    <body>
    
    <a href="javascript:f()">Send an HTTP POST request to a page and get the result back</a>
    
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      而不是使用链接 为什么只是让按钮看起来像链接。 Facebook 是显示为链接的按钮的一个完美示例。它在帖子中有几个按钮,但所有按钮都显示为链接。这是使按钮看起来像链接的Css代码。您可以随时更改链接的外观和感觉(可能是按钮)。

      这里是按钮的 css 代码。

      button {
          background:none!important;
          border:none; 
          padding:0!important;
          /* Do all your Styling to the Button here. It will look like a link instead. */
      }
      

      按钮 HTML 代码。

      <button>Your Button Here.</button>
      

      希望能解决您的问题。谢谢。

      【讨论】:

      • 感谢您的回答。我需要在 Silverlight 应用程序中执行此操作。我之所以使用 HyperlinkBut​​ton 控件,并不是因为它的外观,而是因为 Silverlight 框架的限制。
      • 那么我认为我已经重点说明了您的问题吗?
      • 我正在 Silverlight 中开发应用程序。用户界面不是用 HTML/CSS 创建的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      相关资源
      最近更新 更多