0

I have built a site that uses an index page which has a containing div for loading each page's content into.

At first I was including the external js files and doing the initialisations inside each individual page but 8/10 times the page was loaded, the elements relying on plugins being initialised didn't work but would upon a refresh.

Yesterday I changed the structure so that all external files and all initialisations were done in the index page rather than each individual page.

Now, everything seems to work first time but the second time the page is loaded via ajax the plugins aren't initialised.

Here is how I am doing it in my index page. (excuse inline js on the nav - wasn't me!)

// js files included at the top

<div id="navbar">
    <ul class="clearfix">
        <li>
            <a id="myoeHome" onclick="loadContent('/myoe/amb-home.php')" href="javascript:void(0)"> Home </a>
        </li>
        <!-- some more li a's in the nav bar -->
    </ul>
</div>

jQuery

function loadContent(url) {

    // #content is the containing div where each page is loaded into
    $("#content").load(url, function() {

        if (url == '/myoe/amb-home.php') {

            // initialisations etc. for the particular page

        }

    });


}

Any ideas on what I could do to improve the structure? There are even functions inside the loadContent function because I just moved all js for each page into its own if block.


I would say the best way is to POST that token to the other application and then let it handle it, however you can't actually do a RedirectWithPost() in MVC..

Well you can actually post to the other application with something like new System.Net.Http.HttpClient(), but you wouldn't actually be going to the new page but handling the response locally.

How about if you base64encode your XML, and then redirect to the new application via a standard Redirect with your token in the query string ?

Redirect(string.Concat(url, "?token=",  Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(token))));
4

1 に答える 1

0

これが私の解決策です。それが役に立ったことを願っています。

HTML

<div id="navbar">
    <ul class="clearfix">
        <li>
            <a id="myoeHome"> Home </a>
        </li>
        <!-- some more li a's in the nav bar -->
    </ul>
</div>

<div id="content"></div>

JS

$("#myoeHome").live("click",function(){

loadContent('/myoe/amb-home.php');
});​​​​​​​​​​​​


    function loadContent(url) {

    // #content is the containing div where each page is loaded into
    $("#content").load(url, function() {

        if (url == '/myoe/amb-home.php') {

            // initialisations etc. for the particular page

        }

    });


}
​

</p>

于 2012-10-17T09:00:54.353 に答える