Skip to content

Send ajax request from react component tol local handler. #289

@maddog2299

Description

@maddog2299

I am newbie in react + node js developing. For start learning this technologies I decided to use react-webpack-generator and I like it for simplicity. But I have a question. Can I send ajax query from react component to node.js handler? In browser I always get 404 error, but I dunno why, because my handler located in the same directory as my component.

Example of code :

setAjaxQuery(){
        $.ajax({
            type: 'POST',
            url: './fileHandler.js',
            success: function(){
               console.log('Success!')
            }.bind(this),
            error:  function(){
                console.log('Error!')
            }.bind(this)
        });
    }

render() {

    return (
      <div className="test-component">
            <button onClick={this.setAjaxQuery} value = "test" 
className="test-btn"ref="test">Test</button>
      </div>

    );
 }

Result in browser:

error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions