0

I'm tryin to send data from a ReactJS form to PHP:

handleSubmit(event){
    $(function () {
        $('form').on('submit', function (e) {
            e.preventDefault();
                $.ajax({
                  type: 'post',
                  url: 'Register.php',
                  data: $('form').serialize(),
                  success: function () {
                    alert('form was submitted');
                  }
                });
            });
        });
}

I got this error message

'$' is not defined

<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
1
  • 1
    The error usually indicate that the JavaScript file hasn't been loaded or you are calling the JavaScript code before it has been processed by the JS engine. Commented Sep 11, 2017 at 21:28

2 Answers 2

1

I install JQuery with npm

npm install jQuery --save

then I add jQuery componement to my app

import $ from 'jquery';

And finally it works.

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

Comments

0

Make sure your jquery file is in front of the reactjs file。or you can try:

$ npm i jquery 

then import it

$ import $ from 'jquery'

1 Comment

OP already answered their question... and over 5 hours ago... Not sure why you're submitting the exact same answer.

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.