This is the 25th day of my participation in the August Challenge

(Ajax-POST/same-origin policy/Promise) Check the gaps! Do do do

Can serve as a beginner’s learning route, can refer to, learning progress is not particularly driven! Ongoing update

Combined with their own understanding, simple and comprehensive summary of the basic knowledge points in the process of learning JavaScript in vernacular Chinese, easy to deepen understanding!

Let’s get started! ‘Only a firm foundation can build a tall building ‘! Come on! Take it seriously!

1, combing yesterday’s knowledge of back-end communication – Ajax principle/cache/interface

  • Ajax role: Ajax to achieve no page refresh effect

  • The difference between asynchronous and synchronous:

  • Ajax request for data:

  • Ajax request server data steps:

  • Read server interface

2. Ajax Post

Post can fetch data from the server or send data to the server

Post is the same as GET

When sending data: there is a difference

Post requires setting the request header

ajax.setRequestHeader("content-type"."application/x-www-form-urlencoded");
Copy the code

Set the data to be sent in ajax.send()

3. Same-origin policy

Cognate: same source

When ajax requests data, ensure that the protocol domain names and ports are the same

Same-origin policy: The same-origin policy is an industry standard for browsers to ensure user data security

Ajax cannot access data across domains because of the same origin policy

4. Jsonp is cross-domain

4.1 Cross-domain Principle:

  • Add a script tag to the body by dynamically creating it
  • 2, set upscriptOf the labelsrcThe value is an interface path
  • 3. The interface takes a parameter representing the callback function through which the server data can be retrieved

Jsonp interface and Ajax interface differences:

The json interface:

  • 1. The interface must carry a parameter representing the callback function
  • 2, access to the jSONP interface to get the data is the object class (return value as an object) without type conversion

5. Cors cross domain — cross domain solved by the server

Server data is requested through Ajax, and cross-domain problems are handled across domains on the server

6,promiseobject

Promise – promise

6.1 definition:

var pro = new Promise(function (success, failed) {})
Copy the code

6.2 promiseThe object has three states:

  • pendingongoing
  • resolvedSuccess (solved)
  • rejectedFailed (unsolved)

success —> then

failed —> catch

The promise object executes success, indicating that the promise was successful, followed by the then method

The then method uses:

then(
  function () {execute on success},function () {execute after failure})Copy the code

The promise object executes failed, indicating that the promised event failed, followed by the catch method

6.3 Promise features:

Promise objects are irreversible once their state changes


Preview: Come on, dream chasers

Learning is a continuous process, stick to it, there will be harvest!

Accumulate over a long period, consolidate the foundation, early into Dachang!

It’s not easy to keep it up, and it’s not easy to keep it up. You’re great!

Calm Down & Carry On!


Read more:

Review of previous updates

【 relearn JS】 Every day to strengthen the foundation of the series of articles:

Day24 – Ajax principle/cache/interface, day23- front end also want to understand some databases

【day1】

Day2 various operators, DAY3 data types, DAY4 loop structures & conditional statements, DAY5 functions (emphasis), day6 scopes & events,

【 DAY7 】 object & array method summary, 【day8】 string method & partial sorting,

【 DAY9 】Math object & Wrapper Function, 【 DAY10 】BOM- Browser object model,

【 DAY11 】DOM- Document Object Model

【 DAY13 】Event Event object first known (2),

【 DAY14 】 Event delegate & Drag principle

【 DAY15 】 Drag-and-drop implementation & regular introduction, 【 DAY16 】 regular specific method,

【 DAY17 】cookie, 【day18】ES6,

[DAY19] Js motion function encapsulation

[DAY21] Study and review in the first three weeks

[DAY22] Server and client

More on the way… A long way to go ==-.. – = =