无法在jquery中使用php页面中的Json数据

时间:2016-01-28 14:35:31

标签: php jquery html json parsing

我正在尝试解析使用jquery从php页面发送的json数据,但我得到的结果是:{

我不知道如何解决它, 我在php中创建json数据,如下面的代码:

$load_op_cm = $DBM -> RunQuery("SELECT * FROM at_ops_cmnts WHERE op_id='$op_id'",true,false);
    $row = mysqli_fetch_assoc($load_op_cm);
    $j_result = json_encode($row);
    echo $j_result;

我正在尝试使用jquery解析这些数据,我正在使用Jquery post方法发送数据并获得响应,而我正在尝试获取对我有用的这部分数据: cm_1_1 : 1 不只是这一个,而是所有cm_个变量及其值。

当我以html格式显示响应时,它就像: enter image description here

这是我的jquery代码:

 $(function(){
            var vop_id = localStorage.getItem('op_id');
            $.post("Requests/OPS.php", //Required URL of the page on server
                {   // Data Sending With Request To Server
                    Load_OP_CM : true,
                    op_id : vop_id
                },
                function(response){  // Required Callback Function
                    var result = response;
                    $.each(result, function (i,elem) {
                        $("#Response").text(elem);
                    });

                });

有关如何获取该数据的任何建议吗?

1 个答案:

答案 0 :(得分:1)

首先,您需要解析JSON字符串Compiling assembler: nasm -felf64 "helloworld.asm"... Linking object helloworld.o: ld -melf_x86_64 -o helloworld helloworld.o ... Displaying helloworld.asm asm source: section .text global _start ;must be declared for linker (ld) _start: ;tell linker entry point mov rdx,len ;message length mov rcx,msg ;message to write mov rbx,1 ;file descriptor (stdout) mov rax,4 ;system call number (sys_write) int 0x80 ;call kernel mov rax,1 ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Hello, world!',0xa ;our dear string len equ $ - msg ;length of our dear string Executing linked helloworld executable! ./helloworld | figlet .. _ _ _ _ _ _ _ | | | | ___| | | ___ __ _____ _ __| | __| | | | |_| |/ _ \ | |/ _ \ \ \ /\ / / _ \| '__| |/ _` | | | _ | __/ | | (_) | \ V V / (_) | | | | (_| |_| |_| |_|\___|_|_|\___( ) \_/\_/ \___/|_| |_|\__,_(_) |/ ./helloworld: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped 。 然后当你迭代时,你需要过滤结果,只包括包含' cm _'

的键。
var result = JSON.parse(response);