javascript - 将同一页面的内容加载到 div 中,而不是单击外部链接

标签 javascript jquery html

我使用下面的代码从外部链接加载内容,但速度较慢,具体取决于网络速度。我想将内容托管在同一页面上并从中加载它,或者了解如何无论互联网速度如何都能更快地加载它。

<script>
    function dynamic_Select(ajax_page, currency) {
        $.ajax({
            type: "GET",
            url: ajax_page,
            data: "ch=" + currency,
            dataType: "html",
            //dataType: "text/html", //<--UPDATE: DELETING THIS LINE FIXES EVERYTHING
            //<--UPDATE2: DON'T DELETE; REPLACE "test/html" with "html"
            success: function (html) {
                $("#txtResult").html(html);
            }
        });
    }
</script>

我的html代码是

<input type="radio" name="currency" 
     id="perfectmoney" value="Perfect Money" 
     onChange="dynamic_Select('fetchbuy.php', this.value)" />

最佳答案

您尝试过加载 JQuery 吗?

    $('#your_div').load(url);

当然,您需要 url 是一个 Controller 路径,您可以在其中使用要加载的 html 代码呈现页面

关于javascript - 将同一页面的内容加载到 div 中,而不是单击外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24674727/

相关文章:

javascript - 搜索字段中的最大字符数

javascript - 测试页面上是否存在 div 并将焦点设置为第一个

javascript - bootstrap Popover 里面

html - 源代码超过 10k 行时 IE6 性能问题

html - Firefox:删除表格单元格周围的线

javascript - 逻辑问题,求算法

Javascript 保持滚动位置

javascript - 获取终端响应并将其存储为 Node js中的变量

jquery - 使用@url.action调用部分 View 点击使用jquery

javascript - 我正在编写一个 Javascript 函数来为表格中的每一行涂上不同的颜色。为什么我的代码不起作用?