-3

このリンクでjQueryでAJAXを使用する方法の良い例を見つけました:http: //yensdesign.com/2008/12/how-to-load-content-via-ajax-in-jquery/

index.htmlファイルからファイルにコンテンツを追加しましたview.php(CodeIgniterを使用しています)。

すべて問題ないように見えますが、別のセクションに切り替えたい場合、ページのコンテンツは変更されません(以前と同じコンテンツが表示されます)。

ファイルがCodeIgniterファイルmenu.jsにデータを渡すのに問題があるのではないかと思います。view.php

この問題をどのように解決できるかについて、何か提案をいただけますか?これが他の人にも役立つことを願っています。

Menu.jsファイル:

$(document).ready(function(){
//References
var sections = $("#menu li");
var loading = $("#loading");
var content = $("#content");

//Manage click events
sections.click(function(){
    //show the loading bar
    showLoading();
    //load selected section
    switch(this.id){
        case "home":
            content.slideUp();
            content.load("sections.html #section_home", hideLoading);
            content.slideDown();
            break;
        case "news":
            content.slideUp();
            content.load("sections.html #section_news", hideLoading);
            content.slideDown();
            break;
        case "interviews":
            content.slideUp();
            content.load("sections.html #section_interviews", hideLoading);
            content.slideDown();
            break;
        case "external":
            content.slideUp();
            content.load("external.html", hideLoading);
            content.slideDown();
            break;
        default:
            //hide loading bar if there is no selected section
            hideLoading();
            break;
    }
});

//show loading bar
function showLoading(){
    loading
        .css({visibility:"visible"})
        .css({opacity:"1"})
        .css({display:"block"})
    ;
}
//hide loading bar
function hideLoading(){
    loading.fadeTo(1000, 0);
};

});

javascriptからのアニメーションは機能しています(loading / content / sections)が、実際のコンテンツはhtmlファイルからロードされていません。

私が言ったように、このスクリプトはview.phpファイル(CodeIgniterの「view」ファイル)にコンテンツをロードできないようです

どんな助けでも大歓迎です。

4

1 に答える 1

0

CodeIgniterはサービスを提供する必要がsections.htmlありexternal.htmlます。デフォルトではそうしません。

URLにがview.php使用されているとするとhttp://example.com/index.php/mycontroller/view、jQueryは次のURLのリクエストを送信します。

http://example.com/index.php/mycontroller/sections.html
http://example.com/index.php/mycontroller/external.html

これらのリクエストに対して何をすべきかをCodeIgniterに指示しない限り、CodeIgniterは404を返し、ページのコンテンツは更新されません。

于 2012-05-20T01:36:01.910 に答える