Skip to content

javascript_project_book

Kyusung, Hwang edited this page Oct 3, 2019 · 2 revisions

jQuery.getJSON ๋ถ„์„

jQuery JavaScript Library v1.12.3

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๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š”๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

JSON(JavaScript Object Notation)

๋น„๋™๊ธฐ ๋ธŒ๋ผ์šฐ์ €/์„œ๋ฒ„ ํ†ต์‹  (AJAX)์„ ์œ„ํ•ด, ๋„“๊ฒŒ๋Š” XML(AJAX๊ฐ€ ์‚ฌ์šฉ)์„ ๋Œ€์ฒดํ•˜๋Š” ์ฃผ์š” ๋ฐ์ดํ„ฐ ํฌ๋งท.
๋ณธ๋ž˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด๋กœ๋ถ€ํ„ฐ ํŒŒ์ƒ๋˜์–ด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๊ตฌ๋ฌธ ํ˜•์‹์„ ๋”ฐ๋ฅด์ง€๋งŒ ์–ธ์–ด ๋…๋ฆฝํ˜• ๋ฐ์ดํ„ฐ ํฌ๋งท.

Wiki JSON

AJAX(Asynchronous JavaScript and XML)

๋น„๋™๊ธฐ์ ์ธ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ œ์ž‘์„ ์œ„ํ•ด ์•„๋ž˜์™€ ๊ฐ™์€ ์กฐํ•ฉ์„ ์ด์šฉํ•˜๋Š” ์›น ๊ฐœ๋ฐœ ๊ธฐ๋ฒ•.
Ajax ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋งŒ์„ ์›น์„œ๋ฒ„์— ์š”์ฒญํ•ด์„œ ๋ฐ›์€ ํ›„ ํด๋ผ์ด์–ธํŠธ์—์„œ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค.

Wiki AJAX

XMLHttpRequest Object, over HTTP (file and FTP)

XMLHttpRequest๋Š” Microsoft๊ฐ€ ๋งŒ๋“  JavaScript ๊ฐœ์ฒด(object).
XMLHttpRequest๋Š” HTTP๋ฅผ ํ†ตํ•ด์„œ ์‰ฝ๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

MDN XMLHttpRequest

HTTP(HyperText Transfer Protocol)

WWW ์ƒ์—์„œ ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํ”„๋กœํ† ์ฝœ.
์ฃผ๋กœ HTML ๋ฌธ์„œ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐ์— ์“ฐ์ธ๋‹ค. TCP์™€ UDP๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, 80๋ฒˆ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

Wiki HTTP

HTTP Message

HTTP ๋ฉ”์‹œ์ง€๋Š” ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ ๊ฐ„์— ๋ฐ์ดํ„ฐ๊ฐ€ ๊ตํ™˜๋˜๋Š” ๋ฐฉ์‹.
๋ฉ”์‹œ์ง€์—๋Š” ๋‘ ๊ฐ€์ง€ ํƒ€์ž…์ด ์กด์žฌํ•จ. request๋Š” ํด๋ผ์ด์–ธํŠธ์— ์˜ํ•ด ์ „๋‹ฌ๋˜์–ด ์„œ๋ฒ„์˜ ๋™์ž‘์„ ์ผ์œผํ‚ค๋Š” ๊ฒƒ์ด๊ณ , response๋Š” ๊ทธ์— ๋Œ€ํ•œ ์„œ๋ฒ„์˜ ํšŒ์‹ 

MDN HTTP Messages

TCP/IP Layer

TCP/IP Layer

Chromium XMLHttpRequest implement

Chromium XMLHttpRequest

Chromium SocketStreamHandleClient

SPA(Single Page Application) & SSR (Server Side Rendering)

SPA๋Š” ๊ธฐ์กด์˜ ์ „ํ†ต์ ์ธ ์ƒˆ๋กœ๊ณ ์นจ ๋ฐฉ์‹์˜ ์›น๊ณผ๋Š” ๋‹ฌ๋ฆฌ ํ•„์š”ํ•œ ์ •์ ํŒŒ์ผ์„ ํ•œ๋ฒˆ์—(๋‚˜๋ˆ ์„œ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค) ๋ชจ๋‘ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ณ , ์ดํ›„ ์‚ฌ์šฉ์ž์™€์˜ ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€์šด๋ฐ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋งŒ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ (๋น„๋™๊ธฐ๋กœ) ๋™์ ์œผ๋กœ ๋ฐ›๊ฒŒํ•˜์—ฌ ํŠธ๋ž˜ํ”ฝ์˜ ์ด๋Ÿ‰์„ ์ค„์ด๊ณ , ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ๊ณผ ์œ ์‚ฌํ•œ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ˜•ํƒœ.

SSR์€ ํŽ˜์ด์ง€ ๋กœ๋”ฉ์‹œ๋งˆ๋‹ค ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฆฌ์†Œ์Šค๋ฅผ ์ „๋‹ฌ๋ฐ›์•„ ํ•ด์„ํ•˜๊ณ  ํ™”๋ฉด์— ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ์‹.

SPA ์‹ค์Šต SPA(Sigle Page Applications) ๋ž€ ๋ฌด์—‡์ธ๊ฐ€

SEO (search engine optimization)

๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”๋Š” ์›น ํŽ˜์ด์ง€ ๊ฒ€์ƒ‰์—”์ง„์ด ์ž๋ฃŒ๋ฅผ ์ˆ˜์ง‘ํ•˜๊ณ  ์ˆœ์œ„๋ฅผ ๋งค๊ธฐ๋Š” ๋ฐฉ์‹์— ๋งž๊ฒŒ ์›น ํŽ˜์ด์ง€๋ฅผ ๊ตฌ์„ฑํ•ด์„œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ์˜ ์ƒ์œ„์— ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์ž‘์—…์„ ๋งํ•œ๋‹ค.

How Search Works(YouTube)


Clone this wiki locally