Home > front end >  The client request service side
The client request service side

Time:12-01

The client request service side way
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key technology: v and c #
Author: Huang Futao
Time to write: August 13, 2020,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Pure js writing: use the XMLHttpRequest object
Generally divided into four steps:
1, create a XMLHttpRequest object
2, the XMLHttpRequest object sends a request to the server
(1) : indicate the submission (post request or get request) and submitted to the server specific a method
(2) : specify the file or data to be sent to the server
3, the browser and server connection
4, the server response, the client receives from the client return value
Jquery writing (divided into four kinds, post, get, getJSON, ajax)
A post request, get request, getJSON request
1, url: send a request address,
2, data: data to be sent to the server, generally the use of the form of key-value pairs as parameters, can also use the FormData,
3, the callback: send success callback function, received from the server returns a value, prompt the user operating results
Conclusion:
(1) a post request, get request, writing basic getJSON request are the same, but the role or differentiated,
(2) the getJSON individuals prefer to request data only, do not receive the return value, for example, some modified modal dialog data back to fill,
(3) get request weakness: the url of up to 2048 characters in length, submit the data can be seen above the path of the browser, so insecure, people prefer to use a post request
GetJSON request

A post request and get request


Ajax request (generally used to submit documents, images to the server)
Using ajax requests submitted to specify general way, the path of the submitted, submitted data and receive return values
1, method: submit the way to the post or get
2, the data: data submitted,
3, the path of the submitted url:
4, the success: the callback function, receive the return value from a server
5, at the same time use to set up the processData to false, contentType value is false, the purpose is to tell jQuery don't deal with data and setting up the request header, otherwise you will to send data to compile

Note: when submitting files or pictures, can set the ajax method in the way of submitting to a post request, will get request to compile files or pictures, make the transfer to the server files or pictures of damaged


Conclusion: no matter what the request, is need to set the path of the request, and send data, receive the return value from a server, you just need to understand when to use what way request with respect to OK,


CodePudding user response:

Studied the

CodePudding user response:

Also pay more attention to college students
  • Related