-
Notifications
You must be signed in to change notification settings - Fork 0
javascript_project_book
jQuery.getJSON
getJSON: function( url, data, callback ) {
return jQuery.get( url, data, callback, "json" );
},jQuery.get
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 ) );
};
});jQuery.ajax
ajax: function( url, options ) {
// If url is an object, simulate pre-1.5 signature
if ( typeof url === "object" ) {
options = url;
url = undefined;
}
// Force options to be an object
options = options || {};
...
// Create the final options object
s = jQuery.ajaxSetup( {}, options ),
...
}jQuery.ajaxSetup
ajaxSetup: function( target, settings ) {
return settings ?
// Building a settings object
ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
// Extending ajaxSettings
ajaxExtend( jQuery.ajaxSettings, target );
},jQuery.ajaxSettings
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ?
// Support: IE6-IE8
function() {
// XHR cannot access local files, always use ActiveX for that case
if ( this.isLocal ) {
return createActiveXHR();
}
// Support: IE 9-11
// IE seems to error on cross-domain PATCH requests when ActiveX XHR
// is used. In IE 9+ always use the native XHR.
// Note: this condition won't catch Edge as it doesn't define
// document.documentMode but it also doesn't support ActiveX so it won't
// reach this code.
if ( document.documentMode > 8 ) {
return createStandardXHR();
}
// Support: IE<9
// oldIE XHR does not support non-RFC2616 methods (#13240)
// See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx
// and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
// Although this check for six methods instead of eight
// since IE also does not support "trace" and "connect"
return /^(get|post|head|put|delete|options)$/i.test( this.type ) &&
createStandardXHR() || createActiveXHR();
} :
// For all other browsers, use the standard XMLHttpRequest object
createStandardXHR;jQuery.getJSON function์ browser์ ๋ฐ๋ผ์ XMLHttpRequest object๋ฅผ ์ฌ์ฉํ๋ค๋๊ฒ์ ์ ์ ์๋ค.
๋น๋๊ธฐ ๋ธ๋ผ์ฐ์ /์๋ฒ ํต์ (AJAX)์ ์ํด, ๋๊ฒ๋ XML(AJAX๊ฐ ์ฌ์ฉ)์ ๋์ฒดํ๋ ์ฃผ์ ๋ฐ์ดํฐ ํฌ๋งท.
๋ณธ๋๋ ์๋ฐ์คํฌ๋ฆฝํธ ์ธ์ด๋ก๋ถํฐ ํ์๋์ด ์๋ฐ์คํฌ๋ฆฝํธ์ ๊ตฌ๋ฌธ ํ์์ ๋ฐ๋ฅด์ง๋ง ์ธ์ด ๋
๋ฆฝํ ๋ฐ์ดํฐ ํฌ๋งท.
๋น๋๊ธฐ์ ์ธ ์น ์ ํ๋ฆฌ์ผ์ด์
์ ์ ์์ ์ํด ์๋์ ๊ฐ์ ์กฐํฉ์ ์ด์ฉํ๋ ์น ๊ฐ๋ฐ ๊ธฐ๋ฒ.
Ajax ์ ํ๋ฆฌ์ผ์ด์
์ ํ์ํ ๋ฐ์ดํฐ๋ง์ ์น์๋ฒ์ ์์ฒญํด์ ๋ฐ์ ํ ํด๋ผ์ด์ธํธ์์ ๋ฐ์ดํฐ์ ๋ํ ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค.
XMLHttpRequest๋ Microsoft๊ฐ ๋ง๋ JavaScript ๊ฐ์ฒด(object).
XMLHttpRequest๋ HTTP๋ฅผ ํตํด์ ์ฝ๊ฒ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ ์๊ฒ ํด์ค๋ค.
WWW ์์์ ์ ๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์๋ ํ๋กํ ์ฝ.
์ฃผ๋ก HTML ๋ฌธ์๋ฅผ ์ฃผ๊ณ ๋ฐ๋ ๋ฐ์ ์ฐ์ธ๋ค. TCP์ UDP๋ฅผ ์ฌ์ฉํ๋ฉฐ, 80๋ฒ ํฌํธ๋ฅผ ์ฌ์ฉํ๋ค.
HTTP ๋ฉ์์ง๋ ์๋ฒ์ ํด๋ผ์ด์ธํธ ๊ฐ์ ๋ฐ์ดํฐ๊ฐ ๊ตํ๋๋ ๋ฐฉ์.
๋ฉ์์ง์๋ ๋ ๊ฐ์ง ํ์
์ด ์กด์ฌํจ. request๋ ํด๋ผ์ด์ธํธ์ ์ํด ์ ๋ฌ๋์ด ์๋ฒ์ ๋์์ ์ผ์ผํค๋ ๊ฒ์ด๊ณ , response๋ ๊ทธ์ ๋ํ ์๋ฒ์ ํ์

SPA๋ ๊ธฐ์กด์ ์ ํต์ ์ธ ์๋ก๊ณ ์นจ ๋ฐฉ์์ ์น๊ณผ๋ ๋ฌ๋ฆฌ ํ์ํ ์ ์ ํ์ผ์ ํ๋ฒ์(๋๋ ์๋ ๊ฐ๋ฅํ๋ค) ๋ชจ๋ ๋ค์ด๋ก๋ ๋ฐ๊ณ , ์ดํ ์ฌ์ฉ์์์ ์ํธ์์ฉ ๊ฐ์ด๋ฐ ํ์ํ ๋ฐ์ดํฐ๋ง ์๋ฒ๋ก๋ถํฐ (๋น๋๊ธฐ๋ก) ๋์ ์ผ๋ก ๋ฐ๊ฒํ์ฌ ํธ๋ํฝ์ ์ด๋์ ์ค์ด๊ณ , ๋ค์ดํฐ๋ธ ์ฑ๊ณผ ์ ์ฌํ ์ฌ์ฉ์ ๊ฒฝํ์ ์ ๊ณตํ ์ ์๋ ์ดํ๋ฆฌ์ผ์ด์ ํํ.
SSR์ ํ์ด์ง ๋ก๋ฉ์๋ง๋ค ์๋ฒ๋ก๋ถํฐ ๋ฆฌ์์ค๋ฅผ ์ ๋ฌ๋ฐ์ ํด์ํ๊ณ ํ๋ฉด์ ๋ ๋๋งํ๋ ๋ฐฉ์.
๊ฒ์ ์์ง ์ต์ ํ๋ ์น ํ์ด์ง ๊ฒ์์์ง์ด ์๋ฃ๋ฅผ ์์งํ๊ณ ์์๋ฅผ ๋งค๊ธฐ๋ ๋ฐฉ์์ ๋ง๊ฒ ์น ํ์ด์ง๋ฅผ ๊ตฌ์ฑํด์ ๊ฒ์ ๊ฒฐ๊ณผ์ ์์์ ๋์ฌ ์ ์๋๋ก ํ๋ ์์ ์ ๋งํ๋ค.