Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

javascript - How to Connect Frontend and Backend

As I am a bit beginner

Could anyone help with how can I connect my Front-End (deployed on gh-pages) and backend ( deployed on Heroku) with each other

Frontend consists of simple index.html file and app.js file. And my Backend consist of server.js file.

How should I make changes to both of them. To integrate with each other.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Some more options have popped up these days but the workflow still used in 99% of apps is:

  1. Client makes HTTP request to server
  2. Server receives request and does something with it
  3. Server responds to the request
  4. Client receives response

Remember that your backend and frontend are 2 separately running programs on different machines.

The 2 most used ways to make your front-end communicate with the backend are:

  • To communicate you could make an AJAX call (an HTTP request from your javascript)
  • Complete a form (a form submission send a request to where the Action attribute points)

There are quite a few more possibilities these days but these are the ones you should probably look at first :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...