我將數據發佈到cgi腳本並以json格式獲取響應。存儲到變量中並嘗試將其加載到jqgrid中。但Jqgrid不會加載本地數據,甚至不會顯示錶格。這裏是jquery腳本:JQgrid不適用於本地數據
$(document).ready(function(){
$("#blastform").submit(function(){
$('#blast').hide();
$('#blastresults').show();
$("#datatable").show();
var thistarget = this.target;
jQuery.ajax({
data: $(this).serialize(),
url: this.action,
type: this.method,
dataType: 'html',
error: function() {
$(thistarget).html("<span class='error'>Failed to submit form!</span>");
},
success: function(res) {
// $('#blastresults').html(res);
}
})
return false;
var mydata=[res];
$("#datatable").jqGrid({
datatype:'local',
data: mydata,
jsonReader: {
repeatitems : false,
},
colNames:['QueryID','SubjectID', 'Identity', 'Align-len', 'Mismatches','Gaps','QStart','QEnd','Suject-start','Subject_end','E.Value','Score'],
colModel:[ {name:'query',index:'query', width:55},
{name:'subject',index:'subject', width:90},
{name:'Identity',index:'Identity', width:100},
{name:'AlignLen',index:'AlignLen', width:80, align:"right"},
{name:'Mismatches',index:'Mismatches', width:80, align:"right"},
{name:'Gaps',index:'Gaps', width:80,align:"right"},
{name:'Qstart',index:'Qstart', width:80,align:"right"},
{name:'Qend',index:'Qend', width:80,align:"right"},
{name:'Sstart',index:'Sstart', width:150, sortable:false},
{name:'Send',index:'Send', width:150, sortable:false},
{name:'Evalue',index:'Evalue', width:10, sortable:false},
{name:'Score',index:'Score', width:10, sortable:false}, ],
rowNum:5,
rowList:[2,3,5,10],
pager: $('#pager2'),
sortname: 'QueryID',
//imgpath: '/var/www/test/images',
viewrecords: true,
sortorder: 'desc',
loadonce: true,
height: '500px',
width:'1000px',
altRows: true,
pgbuttons: true,
caption: 'Blast Results'
});
$("#datatable").jqGrid('navGrid','#pager2', {position: 'right'});
jQuery("#datatable").jqGrid('navGrid','#blastresults',{edit:false,add:false,del:false});
}
);
});
來自Ajax調用的響應是:
[ {"Mismatches":"6","subject":"Ca7","query":"AB-Contig743","Send":"17305359","Gaps":"1","AlignLen":"1119","Score":"2113","Identity":"99.37","Evalue":"0.0","Sstart":"17304241","Qstart":"33","Qend":"1150"}, {"Mismatches":"1","subject":"Ca7","query":"AB-Contig743","Send":"41349183","Gaps":"0","AlignLen":"26","Score":"44.1","Identity":"96.15","Evalue":"0.032","Sstart":"41349208","Qstart":"614","Qend":"639"}, {"Mismatches":"0","subject":"Ca7","query":"AB-Contig743","Send":"22007817","Gaps":"0","AlignLen":"20","Score":"40.1","Identity":"100.00","Evalue":"0.51","Sstart":"22007836","Qstart":"672","Qend":"691"}, {"Mismatches":"2","subject":"C11062332","query":"AB-Contig743","Send":"101","Gaps":"0","AlignLen":"29","Score":"42.1","Identity":"93.10","Evalue":"0.13","Sstart":"129","Qstart":"714","Qend":"742"}, {"Mismatches":"2","subject":"Ca5","query":"AB-Contig743","Send":"10391193","Gaps":"0","AlignLen":"29","Score":"42.1","Identity":"93.10","Evalue":"0.13","Sstart":"10391165","Qstart":"714","Qend":"742"}, {"Mismatches":"0","subject":"scaffold438","query":"AB-Contig743","Send":"55788","Gaps":"0","AlignLen":"20","Score":"40.1","Identity":"100.00","Evalue":"0.51","Sstart":"55769","Qstart":"1175","Qend":"1194"}, {"Mismatches":"0","subject":"scaffold1613","query":"AB-Contig743","Send":"56169","Gaps":"0","AlignLen":"20","Score":"40.1","Identity":"100.00","Evalue":"0.51","Sstart":"56188","Qstart":"367","Qend":"386"}]
請幫我找出錯誤。提前致謝。
是否mydata c保留所需的數據?你用螢火蟲檢查過嗎? – Sharun 2013-04-10 03:43:53
雅我檢查了螢火蟲我得到Ajax響應。我將它存儲到mydata中,以便可以將jqgrid作爲本地數據加載。 – Dadu 2013-04-10 05:56:41
ajax應該是{「page」:1,「records」:1,「rows」:[{「id」:1,「cell」:[「AB-Contig743」,「Ca7」,「99.37」, 「1119」, 「6」, 「1」, 「33」, 「1150」, 「17304241」, 「17305359」, 「0.0」, 「2113」]}], 「總」:1}。爲什麼返回空值? – Sharun 2013-04-10 09:17:57