简体   繁体   English

一页的Ajax加载div从另一页调用

[英]Ajax load div of one page called from another page

I am facing with some glitches regarding the ajax load 我面对有关ajax负载的一些故障
OK, so the query is lets say I have page a (picture attached) OK,所以查询是说我有第a页(附加图片)
在此处输入图片说明


the ajax loads the div into the "RESULT" div on clicking the specific id's 单击特定ID时,ajax将div加载到“ RESULT” div中
here is the ajax script & the html i have come so far. 这是到目前为止的ajax脚本和html。 this loads perfectly on the Result div on the page a itself. 这可以完美地加载到页面本身的div上。

<a href="#" id="one" /><br>
<a href="#" id="two" /><br>
<a href="#" id="three" /><br>
<div id="result"  class="functions"></div>


    $.ajaxSetup({
        cache: false
    });
    var ajax_load = "<img class='loading' src='img/load.gif' alt='loading...' />";


    var loadUrl = "content.php";
    $("#one").click(function () {
    $("#result").html(ajax_load).load(loadUrl);
    });

    var load2Url = "content1.php";
    $("#two").click(function () {
    $("#result").html(ajax_load).load(loadUrl);
    });

    var load3Url = "content2.php";
    $("#three").click(function () {
        $("#result").html(ajax_load).load(load2Url);
    });

thing is i need to load the same contents on the result div on page b from another page using the same id calls, lets say page b. 事情是我需要使用相同的ID调用从另一个页面的另一页上将相同内容加载到页面b的结果div上,让我们说页面b。
在此处输入图片说明


the concept is, on page b, the id is clicked, it LOADS page a first & loads the content on "RESULT" div. 这个概念是,在页面b上,单击ID,它首先加载页面并在“ RESULT” div上加载内容。 both pages are on the same server 两个页面都在同一台服务器上
Would really appreciate any assistance. 非常感谢您的协助。 thank you. 谢谢。

One way to handle it will be to pass the dynamic item as a request parameter like in page b use the url /pagea.html?section=one etc 一种解决方法是将动态项目作为请求参数传递,例如在页面b中使用url /pagea.html?section=one

Then on page load 然后在页面加载

$(function(){
    var location = window.location.href;
    var page = location.substring(location.indexOf('=') + 1);
    $('#' + page).trigger('click');
})

You got your loadUrl 's in the wrong pace they should be inside of the function otherwise it's value is the last value it was set to which is content2.php 您以错误的步调loadUrlloadUrl ,它们应该放在函数内部,否则它的值是它设置为content2.php的最后一个值

jsFiddle Demo jsFiddle演示

$.ajaxSetup({
    cache: false
});

var ajax_load = "<img class='loading' src='img/load.gif' alt='loading...' />";

$("#one").click(function () {
    var loadUrl = "content.php";
    $("#result").html(ajax_load).load(loadUrl);
});

$("#two").click(function () {
    var loadUrl = "content1.php";
    $("#result").html(ajax_load).load(loadUrl);
});

$("#three").click(function () {
    var loadUrl = "content2.php";
    $("#result").html(ajax_load).load(loadUrl);
});

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

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