Ad

Use AJAX To Parse Content Of Page

- 1 answer

I'm developing a project in React and I need to make an AJAX call to get the source of a page.

I'm not familiar with AJAX, so I looked here: https://facebook.github.io/react/tips/initial-ajax.html

They are using the following method to get a gist from Github.

componentDidMount: function() {
    $.get(this.props.source, function(result) {
      var lastGist = result[0];
      if (this.isMounted()) {
        this.setState({
          username: lastGist.owner.login,
          lastGistUrl: lastGist.html_url
        });
      }
    }.bind(this));
  },

I want to change this to retrieve the contents of the page(which is in plain text) that I am accessing.

How could I do that?

Ad

Answer

Read the docs for AJAX here.

Doing

$.get('http://example.com/my-url', function(result) {
     console.log(result);
});

should do the trick.

Ad
source: stackoverflow.com
Ad