前端之家收集整理的这篇文章主要介绍了
ajax-返回json,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
function qSubType(selobj){ if(selobj!=null){ var caseSubType=document.getElementById("caseSubType"); caseSubType.options.length=0;//清空select下拉框 if(selobj.value.length!=0){ jQuery.ajax({ type:"POST",url:"${ctx}/partner/product.do?method=qProductSubType",//处理请求的action
方法 //data:"selectId="+jQuery("#"+selectId).val(),//传递的参数 data:{'name':selobj.options[selobj.selectedIndex].text,'id':selobj.options[selobj.selectedIndex].value},//传递的参数 dataType:"html",success:function(data) { if(data!=null&&data!=''){ data=eval('('+data+')'); if(data.subtype!=null&&data.subtype!=''){ var subtypearray=data.subtype; if(subtypearray!=null&&subtypearray.length!=0){ for(var i=0;i<subtypearray.length;i++){ var temp=subtypearray[i]; var value=temp.remark; var text=temp.name; caseSubType.options.add(new Option(text,value)); } } } } },error : function() { //alert("审核失败!"); } }); } } } --返回json {subtype:[{"deleted":0,"flag":0,"id":1027,"mark":"云主机产品","name":"云主机虚拟机","parent_id":1026,"remark":"1"},{"deleted":0,"id":1028,"name":"云主机物理机","remark":"2"},"id":1029,"name":"定制云虚拟机","remark":"3"},"id":1030,"name":"定制云物理机","remark":"4"}]} --java String json="{subtype:\"\"}"; JSONArray jo = JSONArray.fromObject(productSubTypeList); json="{subtype:"+jo.toString()+"}";
原文链接:https://www.f2er.com/ajax/166821.html