Use Express server
Contents in server.js:
get and post servers
Contents in server.js:
It can also be written as app.all( ' / jquery-server ' , ( request , response )=>{
//all can accept all types of requests such as get, post, delete, etc.
})
1. jQuery sends Ajax get request
html content :
Contents in server.js:
Declare an object, convert it into a json string and pass it to the browser
Set [type] to 'json' to set the format of the returned content
The returned result is a js object
2. jQuery sends Ajax post request
content in html
Contents in server.js
There is also a general method:
$ajax({
// Request address: url
url: 'http://127.0.0.1:8000/server',
// Parameter : data [Note that data is also an object]
data : {a:100 , b:200 }, //{ a=100, b=200}
// Request type: type
type : 'GET', // 'POST'
// Successful callback function (data) The data returned by the server
success : function (data) {
},
//Failed callback function
error : function(){
}
})
Note: { } in () is an object , don't forget!
Replenish: