简体   繁体   中英

Displaying json data in a clear format

How can a value from json data and print out in a html text field. json data are looking like this: {"name":"paul"} but i want to display only paul in my text field. my codeigniter php code are below:

$data['name']= $this->name_model->get_names($obj);

            $this->output->set_content_type('application/json');
           $this->output->set_output(json_encode($data));
           $string = $this->output->get_output();
           echo $string;

jquery,ajax codes are below:

if(obj != ''){
        $.ajax({
            url:"<?php echo base_url();?>Geting_names/name_listing",
            method:"POST",
            dataType: "text",
            data: {obj},
            success:function(resp){

            $("div#sending_field").html('<div class="alert alert-success">' + resp +'</div>');

Try this:

In Javascript success method

var obj1 = JSON.parse(resp);

$("div#sending_field").html('<div class="alert alert-success">' + obj1.name +'</div>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM