First of all, jquery’s get method and post method are both encapsulations of ajax, see the source code
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
// Shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
// The url can be an options object (which then must have .url)
return jQuery.ajax( jQuery.extend( {
url: url,
type: method,
dataType: type,
data: data,
success: callback
}, jQuery.isPlainObject( url ) && url ) );
};
} );`
Then, how can I bring cookies when sending a request? When the ajax method sends a request, it will automatically bring the cookie of the domain name you logged in, and you do not need to set it.
So, Jquery’s $.get() method will always bring cookies
When used, the client will automatically bring the cookie, and jquery has been encapsulated. If you want to customize the cookie yourself, you can use the $.cookie plug-in to set the client cookie and finally get it.
For debugging, you can open the console F12 and view the information in the request header on the network
First search for the cookies option in the console Application to see if the cookies settingsget were successful. If it is set up, the client will automatically bring cookie to every page under the same domain name.
When sending a request, the browser will automatically carry the cookie and pass it to the background. Only the localStorage/sessionStorage parameters need to be passed asynchronously as parameters
You should have $.support.cors cross-domain not turned on. Just add the end code withCredentials. In addition, the backend must also be configured with cross-domain.
Under the same domain, cookies will be automatically included
First of all, jquery’s get method and post method are both encapsulations of ajax, see the source code
} );`
Then, how can I bring cookies when sending a request?
When the ajax method sends a request, it will automatically bring the cookie of the domain name you logged in, and you do not need to set it.
So, Jquery’s $.get() method will always bring cookies
When used, the client will automatically bring the cookie, and jquery has been encapsulated. If you want to customize the cookie yourself, you can use the $.cookie plug-in to set the client cookie and finally get it.
For debugging, you can open the console F12 and view the information in the request header on the network
First search for the
cookies
option in the consoleApplication
to see if thecookies
settingsget
were successful. If it is set up, the client will automatically bringcookie
to every page under the same domain name.When sending a request, the browser will automatically carry the cookie and pass it to the background. Only the localStorage/sessionStorage parameters need to be passed asynchronously as parameters
You should have $.support.cors cross-domain not turned on. Just add the end code withCredentials. In addition, the backend must also be configured with cross-domain.