1

We have a website front end that is written in ReactJS and the backend is being developed in PHP.

Is it possible to call these functions from within ReactJS?

KPM
  • 171
  • 4
  • 22
  • 3
    js runs on the client, php runs on the server. neither can call a function in the other. – Marc B Jul 28 '16 at 15:47
  • Would we need to implement an interface between them such as RESTful? – KPM Jul 28 '16 at 15:49
  • 1
    Make an AJAX call to a page that execute the php function – iyop45 Jul 28 '16 at 15:50
  • 2
    Possible duplicate of [Call php function from javascript](http://stackoverflow.com/questions/7165395/call-php-function-from-javascript) – Chris Jul 28 '16 at 15:56

1 Answers1

3

You can't directly call a PHP method from ReactJS as PHP is a server-side language and ReactJS is a Javascript framework which means it's client-side language.

What you need to do is to send an AJAX request using ReactJS to your server and use the response.

Take a look at this link: https://facebook.github.io/react/tips/initial-ajax.html

The link describes how to load initial data from server using AJAX.

kfirba
  • 4,773
  • 13
  • 38
  • 68