【问题标题】:Where to display $.post information?在哪里显示 $.post 信息?
【发布时间】:2015-07-13 04:36:10
【问题描述】:

我有这个:

$.post("http://www.roblox.com/My/Money.aspx/GetMyTransactions", {"startindex": 20, "transactiontype": "purchase"});

我不知道如何“更新”页面或显示帖子中的信息。帮忙?

编辑:

我只想知道如何更改 div "TransactionsContainer" 的内容

【问题讨论】:

标签: javascript jquery api post


【解决方案1】:
$.post( "test.php", { name: "John", time: "2pm" })
  .done(function( data ) {
    alert( "Data Loaded: " + data );
});

https://api.jquery.com/jquery.post/

【讨论】:

  • 与其只发布代码,还不如解释一下你做了什么以及为什么这样做。
  • 有一个 jquery post 函数的链接,其中包含所有信息,.done() 将在请求后被调用,data 将从链接中返回/读取:)
  • 请阅读meta.stackexchange.com/a/8259/177764,了解为什么 StackOverflow 不认为(仅)包含信息的链接是一个好的答案
【解决方案2】:

您可以为$.post 指定第三个参数,它接受一个函数。该函数将来自服务器的响应作为参数提供。

$.post(
  "http://www.roblox.com/My/Money.aspx/GetMyTransactions",
  {"startindex": 20, "transactiontype": "purchase"},
  function(response) {
    // response contains the response object from the server.
    $('[some selector]').text(response);
  }
);

【讨论】:

    【解决方案3】:

    你可以试试:

    <script>
    $(document).ready(function(){
        $.post("http://www.roblox.com/My/Money.aspx/GetMyTransactions", {"startindex": 20, "transactiontype": "purchase"}, function(result){
            $("span").html(result);
        });
    });
    </script>
    
    <span>Result will be displayed here</span>
    

    阅读更多关于jQuery .post

    【讨论】:

    • 有没有办法只改变整页的内容? (我在 Google Chrome 控制台中使用它。)
    • @LoganRichey $("body").html(result);将用您的结果替换正文的整个 html...
    • @sharf this: gyazo.com/ac92d53a5496913fbf47d4d4b520dda9 并且页面不会加载。我假设这是因为错误。
    • www.roblox.com 与请求页面是否在同一个域中?
    • @PedroLobito 是的。它在roblox.com/My/Money.aspx#/#MyTransactions_tab 上,我使用带有谷歌浏览器检查元素的网络选项卡检查了 GetMyTransactions API
    猜你喜欢
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多