2012-01-05 72 views
0

我正在創建一個應用程序,其中頁面內容被更改並通過AJAX(和hashchange jQuery腳本)動態替換。出於某種原因,在動態更改的AJAX內容中,選擇表單選項沒有顯示出來。例如這裏:選擇選項沒有顯示

http://socialbungy.com/newsite/sweeps_temp_facebook/TAB_TEMP1/#enter.php

但是,如果我運行頁面,沒有裝載/改變通過AJAX的內容(除去在URL中的#標記),選擇表單元素的作品,因爲它是應該的。

http://socialbungy.com/newsite/sweeps_temp_facebook/TAB_TEMP1/enter.php

這是我的命!請幫忙。從來沒有遇到過這樣的問題。甚至不知道從哪裏開始。但這裏是我認爲的動態腳本是問題。雖然找不到與選擇框的任何衝突。是什麼賦予了?

$(function() { 

var newHash  = "", 
    $mainContent = $("#appContent"), 
    $pageWrap = $("#page-wrap"), 
    baseHeight = 0, 
    $el; 

$pageWrap.height($pageWrap.height()); 
baseHeight = $pageWrap.height() - $mainContent.height(); 

    $("nav").delegate("a", "click", function() { 
     window.location.hash = $(this).attr("href"); 
     return false; 
    }); 
    $("#buttonWrap").delegate("a", "click", function() { 
     window.location.hash = $(this).attr("href"); 
     return false; 
    }); 

$(window).bind('hashchange', function(){  
    newHash = window.location.hash.substring(1);   
    if (newHash) { 
     $mainContent 
      .find("#guts") 
      .slideToggle(500, function() { 
       $mainContent.hide().load(newHash + " #guts", function() { 
        $mainContent.slideToggle(500, function() { 
         $pageWrap.animate({ 
          height: baseHeight + $mainContent.height() + "px" 
         }); 
        }); 
        $("nav a").removeClass("current"); 
        $("nav a[href="+newHash+"]").addClass("current"); 

        //RE-FIRE OTHER SCRIPTS ON AJAX CONTENT LOAD 

        //Phone Field Format 
        $(function() { 
         $("#phone").mask("(999) 999-9999",{placeholder:" "}); 
        }); 

       }); 
      }); 
    };       
}); 

$(window).trigger('hashchange'); 

});

+0

哈,沒有大呼小叫哥們,如果我是它會是我自己。不是我要求幫助的人。 :) – 2012-01-05 21:09:31

+0

這只是一個瘋狂的猜測,但是可能是因爲你的頁面被服務器解釋爲純HTML,而不是PHP?在URL的哈希部分有.php擴展名不會觸發它被服務器解釋爲php。也許如果你使用的主頁是HTML文件,你可以改爲PHP文件。 – 2012-01-05 21:12:31

+0

這並越過我的腦海裏,但我使用這個網頁,這是php以及: http://socialbungy.com/newsite/sweeps_temp_facebook/TAB_TEMP1/#index.php – 2012-01-05 21:17:16

回答

1

您的服務器響應看起來完全正確,但是在插入DOM之後,您的select元素都會變形。我的猜測是load()+ parse-selector是罪魁禍首。與$.ajax試試吧,這樣的事情:

$(function() { 

var newHash  = "", 
    $mainContent = $("#appContent"), 
    $pageWrap = $("#page-wrap"), 
    baseHeight = 0, 
    $el; 

$pageWrap.height($pageWrap.height()); 
baseHeight = $pageWrap.height() - $mainContent.height(); 

    $("nav").delegate("a", "click", function() { 
     window.location.hash = $(this).attr("href"); 
     return false; 
    }); 
    $("#buttonWrap").delegate("a", "click", function() { 
     window.location.hash = $(this).attr("href"); 
     return false; 
    }); 

$(window).bind('hashchange', function(){ 
    newHash = window.location.hash.substring(1); 
    if (newHash) { 
     $mainContent 
      .find("#guts") 
      .slideToggle(500, function() { 
       $mainContent.hide(); 
       $.ajax({ 
        url: newHash, 
        dataType: 'html', 
        success: function(data) { 
         $mainContent.html($(data).find('#appContent').html()); 
         $mainContent.slideToggle(500, function() { 
          $pageWrap.animate({ 
           height: baseHeight + $mainContent.height() + "px" 
          }); 
         }); 
         $("nav a").removeClass("current"); 
         $("nav a[href="+newHash+"]").addClass("current"); 

         //RE-FIRE OTHER SCRIPTS ON AJAX CONTENT LOAD 

         //Phone Field Format 
         $(function() { 
          $("#phone").mask("(999) 999-9999",{placeholder:" "}); 
         }); 
        } 
       }); 
      }); 
    } 
}); 

$(window).trigger('hashchange'); 

}); 

編輯:全碼答案

+0

嗯,你的代碼無法正常工作。但是我可能錯誤地實現了它。另外我沒有使用jQuery 1.7。你能舉一個你提到的定期成功回調的例子嗎?完整的腳本?編輯了 – 2012-01-05 21:52:01

+0

。試試那個。 – glortho 2012-01-05 21:57:53

+0

我還看到'select'通過ajax/load自動關閉標記從服務器返回:'