Javascript-how can I write code on the front end to receive data from the backend?

Source: Internet
Author: User
I am a front-end soon after getting started. Besides HTML and CSS, I know more about JS and JQ. How can I write the backend to connect the data? Usually, I just need to restore the page like the design draft. I am a front-end soon after getting started. Besides HTML and CSS, I know more about JS and JQ. How can I write the backend to connect the data?
Usually, I just need to restore the page like the design draft.

Reply content:

I am a front-end soon after getting started. Besides HTML and CSS, I know more about JS and JQ. How can I write the backend to connect the data?
Usually, I just need to restore the page like the design draft.

RESTFUL API

I feel that ajax is used to asynchronously load data.

Some js interactions on my side may need to be completed by the server, and the results of the complex points will be done by the front-end.

Directly to the front-end interface, the request path can be connected. Not as hard as imagined

Front end $. get ("test. php", {name: "John "});
Backend _ GET ['name']

Front end $. post ("test. php", {name: "John "});
Backend _ POST ['name']

Json is used for data exchange format, and the backend provides you with corresponding interfaces. parameter descriptions are very convenient.

Php School

You can use the native xmlhttprequest object to send a get request and a post request to complete interaction. For jQ, you can use the $ get and $ post methods, but I feel that $ ajax is more useful.

Let's take a look at ajax and learn about js very quickly.
Data is provided in the background. You can call the data interface directly...

In front-end
If Javascript is used for ajax cross-origin, jsonp is used.
If jq is used and $. ajax is used for cross-origin, $. ajax is also used. However, if you need to change the content, Baidu

The general process is that the project manager provides api documents, such as swagger oai documents, and then establishes a front-end model based on the documents. With the help of mock, the local interface is called and submitted and merged to the background. The interface document describes the method of connection. This document can be implemented only after it is determined. The above several parameters indicate that jQuery Ajax is only implemented.

Understanding http is the first step

Interface. The API is the same as the function we usually use. When you pass parameters, the data can be passed to the backend, and whether a return value is required depends on whether your business logic needs to return data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.