Welcome Guest, Not a member yet? Register   Sign In
Return array to AJAX
#3

[eluser]richthegeek[/eluser]
well AJAX implies XML - therefore changing that structure into XML using this function:
Code:
function array_to_xml( $input, $level) {
    $pre = "\n".str_repeat("    ",($level));
    foreach( $input as $key=>$child ) {
        if( is_array( $child ) ) {
            $output .= $pre."<".$key.">".array_to_xml($child, $level+1).$pre."</".$key.">";
        } else {
            $output .= $pre."<".$key.">".$child."</".$key.">";
        }
    }
    return $output;
}

Then with jQuery you can do (remember to return as Content-type:text/xml):
Code:
function( data ) {
$(data).children().each( function() {
   var group_id = $(this).find("group_id").html();
   var subtype_id = $(this).find("subtype_id").html();
   var xname = $(this).find("name").html();

   // do any append() etc here

})
}
Note, I used "xname" because "name" is semi-restricted and can cause cock-ups in various browsers.


Messages In This Thread
Return array to AJAX - by El Forum - 04-06-2008, 06:38 PM
Return array to AJAX - by El Forum - 04-06-2008, 07:00 PM
Return array to AJAX - by El Forum - 04-06-2008, 07:28 PM
Return array to AJAX - by El Forum - 04-07-2008, 03:47 AM
Return array to AJAX - by El Forum - 04-07-2008, 08:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB