Skip to content

Instantly share code, notes, and snippets.

@hanxiaomax
Created December 2, 2014 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanxiaomax/ea33f5cf072fdbd32eb3 to your computer and use it in GitHub Desktop.
Save hanxiaomax/ea33f5cf072fdbd32eb3 to your computer and use it in GitHub Desktop.
关于getJSON的一点点小坑
$(function(){
$("input:radio").change(function(){
var selectedvalue = $("input[name='group']:checked").val();
//使用getJSON会导致每次都从浏览器缓存里面加载json,ajax就可以实现动态的修改json并加载了
$.ajax({
type: "get",
url:'/static/select.json',
cache: false,//必须为false,否则同样会从缓存中加载
dataType : "json",
success: function(data){
$("#apply").empty();
$.each(data,function() {
if (this.catagory==selectedvalue)
{
$.each(this.subcatagory, function() {
$("#apply").append("<option value="+this.name+">" + this.name + "</option>");
});
};
});
}
});
});
});
$(function(){
$("input:radio").change(function(){
var selectedvalue = $("input[name='group']:checked").val();
$.getJSON($SCRIPT_ROOT+"/_getJSON",function(data){
$("#apply").empty();
$.each(data,function() {
if (this.catagory==selectedvalue)
{
$.each(this.subcatagory, function() {
alert(this.name)
$("#apply").append("<option value="+this.name+">" + this.name + "</option>");
});
};
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment