2010-11-12 39 views
0

IM試着來填充複選框,並從一個XML文件中使用jquery通過folloowing代碼中設置它們的值...問題是它不工作任何人可以PLZ告訴我什麼即時杜安錯誤通過jQuery的填充從XML複選框

$(document).ready(function(){ 
$.ajax({ 
       type: "POST", 
       url: "controls.xml", 
       dataType: "xml", 
       success: function(xml) { 
        var node = $(xml).find('node'); 
        var attribute = $(xml).find('node').attr("attribute"); 
        //TODO: do something with data 
$(xml).find('checkbox').each(function() { 
       var value = $(this).text(); // get the value whether the checkbox is checked or not 
       var name = $(this).attr("name"); //get the name attribute 
       var val = $(this).attr("value"); // get the numeric value of the control e.g. 100 

       $("#Controls").append(//append to some parent container 
       $("<input/>") // a new input element 
        .attr("type", "checkbox") //of type checkbox 
        .attr("name", name) // with given name 
        .attr("checked", value) // checked="checked" or checked="" 
        .attr("value", val)//value= specified value     
     ) 
      }); 



       } 
      }); 
}); 

,這裏是我的xml

<?xml version="1.0" encoding="utf-8" ?> 
<RootElement> 
    <checkbox name="StaticPage" value="100"></checkbox> 
    <checkbox name="FlashPage" value="200"></checkbox> 
    <checkbox name="PhotoGalary" value="250"></checkbox> 
    <checkbox name="CompletePackage" value="1000"></checkbox> 
    <checkbox name="DiscountPAckage" value="800"></checkbox> 
</RootElement> 
+4

什麼是你所面對的錯誤/問題? – 2010-11-12 06:12:42

+1

你能給我們一個xml的樣本嗎? – generalhenry 2010-11-12 06:16:41

+1

是你的URL對不對?它說control.xml – kobe 2010-11-12 06:21:11

回答

0

其頗爲尷尬......

我改變

type: "POST" 

type: "GET" 

問題就迎刃而解了...... TNX大家

0

樣本您是否獲得從POST請求的任何輸出?我會用這個來加載XML:

$.get("test.php", function(data) { 
    alert("Data Loaded: " + data); 
}); 

嘗試使腳本alert()在每一個階段,看看它返回,並在那裏去世。這就是我(可憐,但系統地)調試我的JS。

+0

你也可以使用螢火蟲的console.log :) – 2010-11-12 11:28:31

+0

我也喜歡Chrome的Inspector。那些工具包真的可以幫助調試東西! – Blender 2010-11-12 13:44:07