php – Ajax Response Json打印结果表或div数组

我有一个PHP文件的ajax调用,它将数组编码为json数组/对象.我想要做的是将json响应打印成表格式或数组
 div的.我坚持如何处理ajax成功的响应.这是我的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>

这是从服务器返回的json响应.我可以提醒整个json响应,所以我知道它正在ajax方面工作……

{"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"}]}

解决方法:

$(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; 
    });
});

或者你可以像这样使用JSON2.js

JSON.parse(text, reviver)

JSON 2 GITHUB

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...