0

this code I am writing after 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');
                    });
                },

Here I am getting the JSON format code When I return the response it prints so I want to print this data in a textfield

1
  • I'd recommend storing the response in state and in render method write the state value as the value of an input/textarea tag. Commented Dec 16, 2015 at 8:12

1 Answer 1

2

Here's a sample code...

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}/>
      );
    }
});
Sign up to request clarification or add additional context in comments.

8 Comments

Is this not what you want? Please elaborate your question with an example of how/what the text area should display?
The text area displays only name of particular id not a JSON data
Per my original request, please provide the example of the right data which should be visible in the textarea vs what is visible using the sample code I provided. Also, do remove any private data from your code unless you are comfortable sharing it publicly.
This is returning on textarea {"id":"4238","name":"Muddasar","email":"[email protected]","phone":"99855‌​46142","marks":"70"}]
Now this is heading towards hand-holding... Let me leave this as an exercise for you to figure out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.