How to request PHP and BD files on the same server created by React-app

Asked

Viewed 153 times

0

I’m learning how to use the React Framework. In the sending part of form data, and recover this data, I am using ajax with the function of jQuery.

componentDidMount() {

    $.ajax({
      url:"http://localhost:80/contatos/dados-json.php",
      dataType:'json',
      success:function(clientes){
        this.setState({lista:clientes});
      }.bind(this)
    });
}

Only this URL to whom I am requesting is from another server that is located on my machine (a Xampp server).

Translated, they are two local servers on the same machine

In case it’s like this:

  1. React está - localhost:3000 (npm create-React-app)
  2. PHP and BD files - localhost:80 (Xampp)

The problem with this is that I keep making cross server requests, and end up giving more problems to work.

I wanted to know how to put: PHP and BD files on the same React server?

  • The PHP server is on the same machine as REACT, but on different local servers, one ta on localhost:3000 and the other localhost:80, the way ta ai, ta is working, but it is complicated because it is cross server, I want to put these PHP and BD files on the same REACT server, you know? @wmsouza

  • I am using, npm create-React-app, already comes with Node, webpack etc installed

  • React: C: Users W8 Desktop curso-React PHP files: C: xampp htdocs contacts

  • 1

    Take the files, HTML and Javascript that were compiled by Webpack and put inside a directory on your server PHP.

  • But I lose Node.js? resources or React will use it the same way?

  • 1

    The features that your application will use will be compressed by Webpack, your application will work normally, only by a server PHP. It’s like you put your website on the server, and that’s it.

  • Um entendi vlw

  • Rodrigo, did you get a solution? I have the same problem

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.