Ajax Response Json Print result in table or div array

I have an ajax call to a php file that encodes the array into a json array/object. What I am trying to do is to print the json response into a table format or an array of div's. I am stuck on how to handle the response on ajax success. Here is my ajax..

<script>
    $(document).ready(function(){
        $("#adapter").keyup(function()
        {
            var adapter = $(this).val();
            var dataString = 'searchword='+ adapter +'&format=json' ;
            if(adapter=='' || adapter < 2 )
            {
                $("#display3").hide('');        
            }
            else
            {
                $.ajax({
                    type: "POST",
                    url: "ajax/phpfile",
                    data: dataString,
                    cache: false,
                    success: function(data) 
                    {
                        var myObj = data;
                        ///NOT how to print the result and decode in html or php///
                    }
                });
            }return false; 
        });
    });
</script>

Here is the json response back from the server. I can alert the whole json response, so I know it is working on the ajax side...

{"Result":[{"ptos":{"PTOMasterID":"1","PTOMasterPart":"828B-U6805-L1CX","PTOSeriesUniqueID":"22","PTOPrice":"2715.78","PTOSeries":"82","PTOMounting":"8B","PTOTransmission":"U68","PTOSpeed":"05","PTOShifter":"L","PTOAssemblyID":"1","PTOShaftID":"C","PTOSpecialFeature":"X","PTODate":"2011-11-30 17:28:10"}},{"ptos":{"PTOMasterID":"2","PTOMasterPart":"828B-U6805-L3CX","PTOSeriesUniqueID":"22","PTOPrice":"2715.78","PTOSeries":"82","PTOMounting":"8B","PTOTransmission":"U68","PTOSpeed":"05","PTOShifter":"L","PTOAssemblyID":"3","PTOShaftID":"C","PTOSpecialFeature":"X","PTODate":"2011-11-30 17:28:10"}]}

Answers


$(document).ready(function(){
    $("#adapter").keyup(function()
    {
        var adapter = $(this).val();
        var dataString = 'searchword='+ adapter +'&format=json' ;
        if(adapter=='' || adapter < 2 )
        {
            $("#display3").hide('');        
        }
        else
        {
            $.ajax({
                type: "POST",
                dataType: "json", //set this to json
                url: "ajax/phpfile",
                data: dataString,
                cache: false,
                success: function(data) 
                {
                    var myObj = data;
                    ///NOT how to print the result and decode in html or php///
                    console.log(myObj); //to see the object
                }
            });
        }return false; 
    });
});

Alternatively you could use JSON2.js like so

JSON.parse(text, reviver)

JSON 2 GITHUB


Need Your Help

How to call setTabColor() from onTabChanged?

android android-tabhost

I wanted to change the background of Android tab widget. So I used this code

Display Map in Android?

android google-maps-api-3

i am developing one application in that i want to display map on my device Android 2.3.3, it not display shows error in my log cat

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.