2010-11-12 40 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