populating checkboxes from xml through jquery
im tryin to populate check boxes and set their values from a xml file using jquery by folloowing code... the problem is its not working can anybody plz tell me whats im doin wrong
$(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 = $开发者_Python百科(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
)
});
}
});
});
here is a sample of my 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>
Are you getting any output from your POST request? I would use this to load the XML:
$.get("test.php", function(data) {
alert("Data Loaded: " + data);
});
Try making the script alert()
at every stage to see what it returns and where it dies. That's how I (pathetically, but systematically) debug my JS.
its rather embarrassing ...
i changed
type: "POST"
to
type: "GET"
problem solved ... tnx everybody
精彩评论