Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsing out ajax json results

Tags:

json

jquery

ajax

I'm trying to parse out some data thats returned from a web service via json with the following code.

        function getADData() {
        var strSearch = $('#txtSearch').val()
        var ajaxData = "{ 'PartNameString': '" + strSearch + "' }";
        $.ajax({
            type: "POST",
            url: "/Services/ActiveDirectoryInterop.asmx/SearchUsers",        
            data: ajaxData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success:populateTable
        });
    }

    function populateTable(result) {
        alert(result["d"].length);
    }

Data Returned is this.

{"d":{"Columns":["UserID","Name","Email"],"Rows":[["U99999","Lees, Smith","[email protected]"],["U99999","Lees, Mark","[email protected]"],["99999","Lees, Bob","[email protected]"],["U999999","Lees, John","[email protected]"],["U999999","Lees, Jim","[email protected]"]]}}

What the alert though jsut returns undefined. So i know I'm missing something and it probably has to do with the nesting of the JSON. Can someone point me in the right direciton for some materials or code that shows me how to possibly traverse data like what i'm recieving.

like image 690
Gary.Townsend Avatar asked Nov 16 '25 05:11

Gary.Townsend


1 Answers

Try this instead:

alert(result.d.Columns.length);

And read up on that weirdo 'd'.

like image 149
Kon Avatar answered Nov 18 '25 20:11

Kon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!