首先,jquery的get方法和post方法都是对ajax的一种封装,见源码
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 ) );
};
} );`
然后,发送请求的时候怎么才能带上cookie?
ajax方法发送请求的时候,会自动带上你所登录的域名的cookie,不需要你设置。
所以,Jquery的$.get()方法什么时候都会带上cookie