jquery - How do I check whether the result data set from an AJAX call has only 1 parent node? -


please refer if statement in code:

function createprojecttree(sc) {     $.ajax({         type: "post",         url: "../api/projects/searchprojects",         data: sc,         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: function(data)         {             if (data contains 1 parent node)             {                 //redirect page x page             }             else             {                 buildtree(data);             }         },     }); } 

the result of call xml , need check whether has 1 parent node (regardless of number of children).

how go doing this?

you can use length property of jquery object:

if ( $(data).length === 1 ) {    // ... } 

note if response's type of request xml, should set datatype property xml , not json.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -