2012-12-09 72 views
1

我想實現這樣的事情。 http://app.maqetta.org/mixloginstatic/LoginWindow.html從Ajax調用加載Dojo表格

我想登錄頁面加載,但如果你點擊註冊按鈕,然後ajax將用註冊表單替換登錄表單。

我有這個使用此代碼

dojo.xhrGet({ 
     // The URL of the request 
     url: "'.$url.'", 
     // The success callback with result from server 
     load: function(newContent) { 
      dojo.byId("'.$contentNode.'").innerHTML = newContent; 
     }, 
     // The error handler 
     error: function() { 
      // Do nothing -- keep old content there 
     } 
    });' 

唯一的問題是新的形式,只是加載了作爲一個正常的形式,而不是一個道場的形式工作。我試圖用相位器返回一些腳本,但它沒有做任何事情。

<div id="loginBox"><div class="instructionBox">Please enter your details below and click <a><strong>signup</strong> 
    </a> to have an activation email sent to you.</div> 
    <form enctype="application/x-www-form-urlencoded" class="site-form login-form" action="/user/signup" method="post"><div> 
    <dt id="emailaddress-label"><label for="emailaddress" class="required">Email address</label></dt> 
    <dd> 
    <input 0="Errors" id="emailaddress" name="emailaddress" value="" type="text"></dd> 
    <dt id="password-label"><label for="password" class="required">Password</label></dt> 
    <dd> 
    <input 0="Errors" id="password" name="password" value="" type="password"></dd> 
    <dt id="captcha-input-label"><label for="captcha-input" class="required">Captcha Code</label></dt> 
    <dd id="captcha-element"> 
    <img width="200" height="50" alt="" src="/captcha/d7849e6f0b95cad032db35e1a853c8f6.png"> 
    <input type="hidden" name="captcha[id]" value="d7849e6f0b95cad032db35e1a853c8f6" id="captcha-id"> 
    <input type="text" name="captcha[input]" id="captcha-input" value=""> 
    <p class="description">Enter the characters shown into the field.</p></dd> 
    <dt id="submitButton-label">&nbsp;</dt><dd id="submitButton-element"> 
    <input id="submitButton" name="submitButton" value="Signup" type="submit"></dd> 
    <dt id="cancelButton-label">&nbsp;</dt><dd id="cancelButton-element"> 
    <button name="cancelButton" id="cancelButton" type="button">Cancel</button></dd> 
     </div></form> 

    <script type="text/javascript"> 

      $(document).ready(function() { 

       var widget = dijit.byId("signup"); 

       if (widget) { 
        widget.destroyRecursive(true); 
       } 

       dojo.parser.instantiate([dojo.byId("loginBox")]); 
       dojo.parser.parse(dojo.byId("loginBox")); 
      }); 

      </script></div> 

任何意見,我怎麼能得到這個加載作爲道場形式。順便說一句,我正在使用Zend_Dojo_Form,如果我直接運行代碼,然後一切工作發現,但通過Ajax它不工作。謝謝。


更新

我發現,如果我在上面加載在我的行動的形式和運行__toString()它工作時,我從阿賈克斯加載的形式。它必須在__toString中做準備()

回答

1

首先;您需要在HTML運行道場解析器,它接受的數據道場型(FKA的dojoType)屬性,像這樣:

dojo.parser.parse(dojo.byId("'.$contentNode.'")) 

當然,這隻會實例在道場類型設置爲dijit的例如(對於html5 1.7+語法)<form data-dojo-type="dijit.form.Form" action="index.php"> ... <button type="submit" data-dojo-type="dijit.form.Button">Send</button> ... </form>

因此,您需要更改設置爲innerHTML的ajax內容,以便解析器重新識別dijit.form.Form類型的表單。也就是說,我敦促人們使用一整套dijit.form。*元素作爲輸入字段。

在問候:

$(document).ready(function() {}); 

此功能將永遠不會被調用。您添加了innerHTML的document已準備好了,可能還需要很長時間。

關於Zend公司在這個問題:

特殊照顧最有可能呈現從Zend_道場型形式上面的輸出形式。如果渲染器設置爲programmatic,您將在上面看到一個包含ID => dojoType映射註冊表的腳本。將<script>作爲innerHTML屬性值插入時的行爲,腳本在大多數情況下(!)不運行。

你應該嘗試類似這樣的僞東西表單控制器:

如果請求AJAX dojoHelper組佈局declarative
其他dojoHelper組佈局programmatic