0

what could be the reason of this error?

this is my code

componentDidMount() {
    $.get("/api/v1/schools", function(result) {
        this.setState({
            dataSchools: result,
        });
    }.bind(this));
}
12
  • add the jquery script ? Commented May 12, 2016 at 4:21
  • did you include jQuery library? Commented May 12, 2016 at 4:21
  • yes, i have included it Commented May 12, 2016 at 4:22
  • 4
    Please god no don't add jquery just to do a xhr request. Use the fetch api with a polyfill why cant i downvote comments Commented May 12, 2016 at 4:22
  • should the jquery ui be included also? Commented May 12, 2016 at 4:24

1 Answer 1

1

Note: I am not recommending use of jquery only for ajax calls in ReactJs application. You can use libraries like superagent or needle etc.

Coming to your error: that jquery is not identified inside your JSX code. The reason is JS script inclusion precedence. Make sure you are including the jQuery library ahead of your bundle Js(the Js generated using your buldlers like webpack or CommonJs). To be in safer side keep the script to include the jQuery library before all other libraries. Because there are many other library which depend upon jQuery to function properly.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

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.