jqGrid: Error: Invalid XML -
i have jqgrid filled custom xml response server. managed run datatype: "xmlstring", when xml string hard-coded locally, managed run when xml response jqxhr.responsetext, , pass xml string, still using datatype: "xmlstring", when set datatype: "xml", following error:
an error occured during request: error: invalid xml:
and after error there listed code of html page of that, instead of xml response, seems odd me.
the error happens when set data: data, or data: jqxhr.responsetext, or data: jqxhr.responsexml.
any ideas on one? when using datatype: "xml", should correct thing should pass jqgrid data - data, jqxhr.responsetext, jqxhr.responsexml or member of data?
also benefit of using datatype: "xml", on datatype: "xmlstring"? if don't manage run datatype: "xml", use datatype: "xmlstring" xml coming response, , there issue approach?
p.s. versions: jqgrid v. 4.7.0, jquery v. 2.1.3, firefox v. 39.0 , ie 11.
<!doctype html> <html> <head> <title></title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> var columnnames = [ "user id", "organization", "email" ]; var columnmodels = [ { name: "userid", visibility: "mandatory", index: "userid", width: 100, xmlmap: '>reference[name="logicalmember"]>object[type="logicalmember"]>attribute[name="login"]'}, { name: "organization", index: "organization", xmlmap:'>reference[name="organization"]>object[type="organization"]>attribute[name="name"]' }, { name: "email", index: "email", width: 80, xmlmap:'>reference[name="emailaddresses"]>object[type="emailaddress"]>attribute[name="address"]'}, ]; var filtermodel = [ { id: 'userid', name: 'user id', renderer: 'text' }, { id: 'organization', name: 'organization', renderer: 'text', rendereroptions: { prompt: 'domain*' } } ]; var xmlmapping = {root:"searchresponse", row:'searchresponse>object[type="contact"]', records:"searchresponse[total-found]", repeatitems:false, id : "[id]"} // page initialization //------------------------------------------------------------------ $(document).ready( function() { var searchrequest = createusersearchrequest('', '', '', '', null, '', '', 50, 1); var usersessionid = sessionstorage.getitem("usersessionid"); $.ajax({ type : "post", datatype : "xml", url : "../../../../api/", headers: { "usersessionid": usersessionid, "include_extended_attributes" : false, "clientversion" : "3.0", "clientapplication" : "someapp", "content-type" : "text/xml" }, data : searchrequest }) .done(function (data, textstatus, jqxhr) { var xml = jqxhr.responsetext; // table ---------------------- var table = $("#table"); table.jqgrid( { data : data, datatype: "xml", colnames: columnnames, colmodel: columnmodels, multiselect: true, fixedloadingdiv: true, onselectrow: selectrow, onselectall: selectallrow, columnchooserbuttonvisible: true, // sort config cmtemplate: { sortable: true }, sortname: "userid", sortorder: "desc", onsortcol: applysort, xmlreader: xmlmapping, emptyrecords: false, columnsstatecontextkey: "some.context", fixedtableheader: true }); table.jqgrid('hideloadingbar'); }) .fail(function (data, textstatus, jqxhr) { alert("server error!"); }); }); </script> </head> <body> <div class="grid-content"> <table id="table"></table> </div> </body> </html>
the first thing recommend verifying whether correctly includes jquery , jqgrid on page. should modify text of question , include version information jquery , jqgrid use. important know web browser , in version use tests.
the next thing recommend using fiddler or developer tools of ie/chrome/firefox trace http traffic between server , client. should examine the exact body , headers of server response. should include information in text of question. important is: value have content-type
header.
one more thing: should start html page in debugger (press f12 start developer tools , start script debugging). see exact place error "invalid xml" take place. can see call stack , line of jquery or jqgrid executed. it's better if use non-minimized version of jquery , jqgrid tests.
updated: code fragment posted shows use jqgrid in th wrong way. first of misunderstand meaning of datatype
parameter.
the options datatype: "xml"
or datatype: "json"
should used in combination url
parameter. datatype: "xml"
without loadonce: true
means implemented server side paging of data , jqgrid should send url
requests load every page of data. don't specified rownum
option, default value 20
used. during creating of jqgrid makes request fill grid url
. if no url specified request current page made.
the parameter data
used jqgrid if use datatype: "local"
. value of data
parameter should array elements represents rows of grid.
so if want load xml data url have use mtype: "post", url: "../../../../api/", datatype: "xml", loadonce: true
. if want make request url separately should use datatype: "xml", datastr: data
. data
can pared xml object or string xml data.
if don't load data static xml file recommend use json instead of xml. it's more both client side , server side.
update 2: can use following options example
datatype: "xml", url : "../../../../api/", loadonce: true, mtype: "post", postdata: searchrequest, ajaxgridoptions: { contenttype: "text/xml", headers: { usersessionid: usersessionid, include_extended_attributes: false, clientversion: "3.0", clientapplication : "someapp" } }
Comments
Post a Comment