get request
$. get() - Send get request
// Parameter 1: request address - Required // Parameter 2: request body - Optional // The request body can be a string or an object // Parameter 3: successful callback function - Optional // Parameter 4: data format to be returned - text/json - Default auto identification data $.get('http://localhost:8888/test/third',{ name:"Zhang San", age:12 },function(res){ console.log(res); })
post request
$.post() - Post request
$.post('http://localhost:8888/test/fourth',{ name:"Zhang San", age:12 },res=>{ console.log(res); },'text')
ajax request
$.ajax() - You can send either a get request, a post request, or a JSON request
$.ajax({ url:'http://localhost:8888/test/fourth', // method:'get', // Request mode - method/type type: 'post', data:'name=Zhang San&age=12', dataType:'json', success:function(res){ console.log(this); console.log(res); }, // Parameter 1: ajax object // Parameter 2: error description // Parameter 3: specific error information error:(xhr, err, msg)=>{ console.log(err); console.log(msg); console.log(xhr); }, timeout: 1, // It is specified that the request must be completed within the specified time. If it is not completed, the gateway times out context: $('body'), // Change this cache: false // Cache })
jsonp request
$.ajax({ url:'http://search.jumei.com/ajax_get_assoc_word', data:{ search: 'js', container: 'top_out_search_pop_div', callback: 'jQuery111207226215531963618_1631843362927', _: +new Date() }, dataType:'jsonp', // When sending a jsonp request, dataType is required and the value must be jsonp success:res=>{ console.log(res); }, jsonpCallback: 'searchCallback' // The name of the function to be called in the target address must be placed in the jsonpCallback key })
Global ajax functions
node
nodejs - Is a software installed. The software is used to run js code
The reason why the browser can run js code is that there is a js engine, which is specially used to identify js code
nodejs is to take out the js engine in the browser and make a software - Once you find the js code, you can run it in this software
nodejs is actually a running environment of js, so that js code can run away from the browser
After leaving the browser, there will be no window and document - Unable to run BOM and DOM
Only ECMAScript can be run in nodejs : Variable, operation, judgment, loop, function, object, array, string, time, date, mathematical object, regular, constructor . . . .
Usage:
1. In the command line window, click node to open the console
2.node js file path
Learning commands:
Open a command line window:
1.win+r enter cmd and press enter
2. In the start menu, enter cmd, command prompt / run as administrator
3. In any folder, hold down shift, click the right mouse button and select here to open the powershell window
4. In the path of the file, enter cmd and press enter
5. With the help of vscode, the shortcut key is ctrl+` Right click the current or blank space and select open in terminal
If other opening methods are not easy to use, try whether the administrator can run it first
Instruction (- followed by Apple instruction or abbreviation)
Drive change letter:
Drive letter:
View all files and folders in the current folder:
dir - ls
Enter a folder:
cd Folder path
Go back to the parent folder:
cd ..
You cannot enter a folder across drive letters in windows - Just switch the drive letter first
Create folder:
md Folder name - mkdir Folder name
Delete folder:
rd Folder name - rm - rf Folder name
Create file:
echo Nul > file name - touch File name
Write content:
echo Content > file name - vi File name + a + Write content + : wq
Delete file:
del File name - rm - rf File name
Move files:
move Original file path New file path - mv Original file path New file path
Rename file:
ren Original file name New file name - mv Original file path New file path - give a new name
Clear screen:
cls - clear
View ip address:
ipconfig - ifconfig
Detect network interworking:
ping ip address / domain name
npm related operations
Third party module - Someone else wrote it - We use jQuery / wiper / bootstrap and so on
nodejs provides a tool for downloading third-party modules - Module name
npm - It comes with nodejs
Check whether the tool is available: npm - v
Download command:
npm install Module name - npm i Module name
You can overwrite the original file by downloading it again
Download the specified version of the file: npm i Module name @ version number - The version number does not need to be too specific
Delete downloaded package: NPM uninstall modular - npm un modular
When the download starts, a folder node will be generated_ Modules to generate a package-lock.json file
node_ The folder level in the modules folder is deeply nested, and there are many trivial files
Therefore, when the project goes online, the node is not uploaded_ Modules folder
npm initialization - Record the name and version of the module to be downloaded in a file
Execute npm init command - A package.json file will be generated
Download other modules later and automatically record them in this file
When uploading the project later, just upload the recorded files
According to the recorded files, just download the dependent modules again
Execute command: npm i The recorded modules will be downloaded automatically
If the download fails:
1. Try again
2. Check the network
3. There is a problem with the network of the original website where the file is downloaded
4.n - Use nrm's tools to do this
NPM can download the installation tool: NPM i nrm -- global - npm i Tool name - g
Download and install successfully: nrm -- version
Detect which website downloads faster - nrm test
Switch to the address with the smallest number of milliseconds: nrm use name
NPM can download multiple modules at one time: npm i Module 1 Module 2 Module 3 ...
npm download actually has a cache every time, so after the download fails, you can try to clear the cache:
npm cache clean -f
Manual cache clearing: c: / user / current user / appdata / roaming / NPM cache - Delete