Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在React JS的文本字段中打印JSON数据_Javascript_Json_Reactjs - Fatal编程技术网

Javascript 在React JS的文本字段中打印JSON数据

Javascript 在React JS的文本字段中打印JSON数据,javascript,json,reactjs,Javascript,Json,Reactjs,我在componentDidMount之后编写的代码: componentDidMount: function() { var url = document.URL; var currentId = url.substring(url.lastIndexOf('?') + 4);//getting the current ID from the url var data = {

我在componentDidMount之后编写的代码:

componentDidMount: function() {
                  var url = document.URL;  
                  var currentId = url.substring(url.lastIndexOf('?') + 4);//getting the current ID from the url
                  var data = {
                  idtoUpdate: currentId
                  };
                  $.ajax({
                    type: 'POST',
                    url: 'test.php',
                    data: data,
                   success: function(response) {
                    var result = $.parseJSON(response);
                    $("#briefinfo").html(response);//This response will prints the JSON format data which is return by test.php

                   }
                    })
                    .done(function(data) {

                    })
                    .fail(function(jqXhr) {
                    console.log('failed to register');
                    });
                },
在这里,当我返回它打印的响应时,我得到了JSON格式的代码
所以我想在文本字段中打印这些数据,这是一个示例代码

var someComponent = React.createClass({
    getInitialState:function(){
      return {"response":null};
    },
    componentDidMount: function() {
      var url = document.URL;  
      var currentId = url.substring(url.lastIndexOf('?') + 4);//getting the current ID from the url
      var data = {
        idtoUpdate: currentId
      };
      $.ajax({
        type: 'POST',
        url: 'test.php',
        data: data,
       success: function(response) {
        var result = $.parseJSON(response);
        this.setState({"response": response});
       }.bind(this)
      })
      .done(function(data) {

      })
      .fail(function(jqXhr) {
        console.log('failed to register');
      });
    },
    render: function(){
      return (
        <textarea value={this.state.response} readonly={true}/>
      );
    }
});
var someComponent=React.createClass({
getInitialState:函数(){
返回{“response”:null};
},
componentDidMount:function(){
var url=document.url;
var currentId=url.substring(url.lastIndexOf(“?”)+4);//从url获取当前ID
风险值数据={
idtoUpdate:currentId
};
$.ajax({
键入:“POST”,
url:'test.php',
数据:数据,
成功:功能(响应){
var result=$.parseJSON(响应);
this.setState({“response”:response});
}.绑定(此)
})
.完成(功能(数据){
})
.失败(功能(jqXhr){
console.log('注册失败');
});
},
render:function(){
返回(
);
}
});

我建议将响应存储在state中,并在render方法中将state值作为input/textarea标记的值写入。这不是您想要的吗?请举例说明文本区域应如何显示/显示什么?文本区域仅显示特定id的名称,而不是JSON数据。根据我的原始请求,请提供文本区域中应可见的正确数据与使用我提供的示例代码可见的正确数据的示例。此外,除非您愿意公开共享,否则请从代码中删除任何私人数据。这将在文本区域{“id”:“4238”,“name”:“Muddasar”,“email”:muddasar@nadsoftdev.com,“电话”:“99855”‌​46142,“标记”:“70”}]现在这是走向手持。。。让我把这作为一个练习留给你去弄清楚。