嘗試用jquery寫的ajax異步刷新而且組織html文檔javascript
$("li.mod_cate").bind("mouseover",function(){//解決鼠標移動到子模塊中還會觸發ajax的問題 var type = $(this).attr("name"); $.ajax("url"+type+"/", { dataType: "jsonp", data: "", success: function (json) { var jsondata = json.data1; var txtHtml1 = ""; for (var i = 0; i < jsondata.length; i++) { if (jsondata[i].value1.length != 0){ var txthtml2 = "<li><table><tr><td>"+jsondata[i].colname+"</td><td><ul>"; var t1 = ""; for (var j = 0; j < jsondata[i].value1.length; j++){ var txtHtml3 = "<li><a href=\"/books/"+jsondata[i].value1[j].colid+jsondata[i].colname+"/"+jsondata[i].value1[j].colname+"\">"+jsondata[i].value1[j].colname+"</a></li>"; var t1 = t1 + txtHtml3; } var t3 = txthtml2+t1+"</ul></td></tr></table></li>";} else{ var t3 = "<li><table><tr><td>"+jsondata[i].colname+"</td></tr></table></li>"; } var txtHtml1 = txtHtml1+t3}; $("#"+type).html(txtHtml1); //自定義選擇器 } }); }).on("mouseout",function(){ $(this).unbind("mouseover"); //解決鼠標移動到子模塊中還會觸發ajax的問題 });
後臺jsonhtml
javascriptFunction = request.args["callback"] return javascriptFunction + "(" + json.dumps(kinds) + ");"