ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î

jQuery.getScript, JavaScript ÆÄÀÏÀ» ·ÎµåÇÏ°í ½ÇÇà
8³â Àü
°³¿ä : HTTP GET ¹æ½Ä ¿äûÀ» ÅëÇØ ¼­¹ö·ÎºÎÅÍ ¹ÞÀº JavaScript ÆÄÀÏÀ» ·ÎµåÇÏ°í ½ÇÇàÇÕ´Ï´Ù.

jQuery.getJSON( url [, data] [, success(data, textStatus, jqXHR)] )
url Á¤º¸¸¦ ¿äûÇÒ URL
success(data, textStatus, jqXHR) ¿äûÀÌ ¼º°øÇÏ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö
ÀÌ ÇÔ¼öÀÇ °¡Àå °£´ÜÇÑ »ç¿ë¹ýÀº ¾Æ·¡¿Í °°½À´Ï´Ù.
$.ajax({
  url: url,
  dataType: "script",
  success: success
});
½ºÅ©¸³Æ®°¡ ½ÇÇàµÇ¸é ´Ù¸¥ º¯¼ö¿¡¼­ Á¢±ÙÀÌ °¡´ÉÇÏ°í jQuery ÇÔ¼ö¿¡¼­µµ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. Æ÷ÇÔµÈ ½ºÅ©¸³Æ®´Â ÇöÀç ÆäÀÌÁö¿¡ ¿µÇâÀ» ÁÙ ¼ö ÀÖ½À´Ï´Ù.
Success Callback
ÀÌ ÄݹéÇÔ¼ö´Â JavaScript ÆÄÀÏÀ» ¹Ýȯ ¹Þ½À´Ï´Ù. ½ºÅ©¸³Æ®°¡ ÀÌ¹Ì ÀÌ ½ÃÁ¡¿¡¼­ ½ÇÇàµÇ¹Ç·Î ÀÌ°ÍÀº ÀϹÝÀûÀ¸·Î À¯¿ëÇÏÁö ¾Ê½À´Ï´Ù.
$(".result").html("<p>Lorem ipsum dolor sit amet.</p>");
½ºÅ©¸³Æ®´Â ÆÄÀÏÀ̸§À» Âü°íÇÑ ÈÄ ·ÎµåÇÏ°í ½ÇÇàµË´Ï´Ù.
$.getScript("ajax/test.js", function(data, textStatus, jqxhr) {
   console.log(data); //data returned
   console.log(textStatus); //success
   console.log(jqxhr.status); //200
   console.log('Load was performed.');
});
Handling Errors
jQuery 1.5 ºÎÅÍ .fail() ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼ö ÀÖ°Ô µÇ¾ú½À´Ï´Ù.
$.getScript("ajax/test.js")
.done(function(script, textStatus) {
  console.log( textStatus );
})
.fail(function(jqxhr, settings, exception) {
  $( "div.log" ).text( "Triggered ajaxError handler." );
});  
jQuery 1.5 ÀÌÀü ¹öÁ¯¿¡¼­´Â, .ajaxError() Äݹé À̺¥Æ®¿¡ $.getScript() ¿¡·¯ ó¸® ±¸¹®À» Æ÷ÇÔÇؼ­ »ç¿ëÇØ¾ß ÇÕ´Ï´Ù.
$( "div.log" ).ajaxError(function(e, jqxhr, settings, exception) {
  if (settings.dataType=='script') {
    $(this).text( "Triggered ajaxError handler." );
  }
});
Caching Responses
±âº»ÀûÀ¸·Î $.getScript() ÀÇ cache ¼Ó¼º°ªÀº false ÀÔ´Ï´Ù. ½ºÅ©¸³Æ®¸¦ ¿äû½Ã¿¡ URL¿¡ timestamped ¸¦ Æ÷ÇÔÇÏ¿© ºê¶ó¿ìÁ®°¡ Ç×»ó »õ·Î¿î ½ºÅ©¸³Æ®¸¦ ¿äûÇϵµ·Ï ÇϽʽÿÀ. cache ¼Ó¼ºÀÇ Àü¿ª°ªÀ» »õ·Î ¼¼ÆÃÇÏ·Á¸é $.ajaxSetup()¿¡¼­ ÇÏ¼Å¾ß ÇÕ´Ï´Ù.
$.ajaxSetup({
  cache: true
});
¿¹ Á¦  
ij½ÌµÈ ½ºÅ©¸³Æ®¸¦ °¡Á®¿Ã ¼ö ÀÖµµ·Ï $.cachedScript() ÇÔ¼ö¿¡¼­ Á¤ÀÇÇÕ´Ï´Ù.
jQuery.cachedScript = function(url, options) {

  // allow user to set any option except for dataType, cache, and url
  options = $.extend(options || {}, {
    dataType: "script",
    cache: true,
    url: url
  });

  // Use $.ajax() since it is more flexible than $.getScript
  // Return the jqXHR object so we can chain callbacks
  return jQuery.ajax(options);
};

// Usage
$.cachedScript("ajax/test.js").done(function(script, textStatus) {
  console.log( textStatus );
});
À½, ¼ÖÁ÷È÷ ¸»¾¸µå·Á¼­ À§ ¿¹Á¦°¡ ½ÇÇàµÇ¸é ¾î¶»°Ô µÈ´Ù´Â °ÇÁö Á¤È®ÇÏ°Ô ¸ð¸£°Ú½À´Ï´Ù. :-(

¿¹ Á¦  
°ø½Ä jQuery Ä÷¯ ¾Ö´Ï¸ÞÀÌ¼Ç Ç÷¯±×ÀÎ ÆÄÀÏÀ» ·ÎµåÇÏ°í ƯÁ¤ Ä÷¯¸¦ ¹Ý¿µÇÕ´Ï´Ù.
<!DOCTYPE html>
<html>
<head>
  <style>
.block {
   background-color: blue;
   width: 150px;
   height: 70px;
   margin: 10px;
}</style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<button id="go">» Run</button>

<div class="block"></div>

<script>
$.getScript("/scripts/jquery.color.js", function() {
  $("#go").click(function(){
    $(".block").animate( { backgroundColor: "pink" }, 1000)
      .delay(500)
      .animate( { backgroundColor: "blue" }, 1000);
  });
});
</script>

</body>
</html>

jquery.color.js ÆÄÀÏÀ» ¿­¾îº¸¼¼¿ä. ¹«Áö º¹ÀâÇÏ°Ô ¹¹¶ó¹«¶ó µÇ¾î Àֳ׿ä. ±×Áß¿¡ colors = jQuery.Color.names º¯¼ö¿¡ À§ ¿¹Á¦¿¡ ÀÖ´Â blue¿Í pink ¿¡ ´ëÇÑ 16Áø¼ö °ªÀÌ µé¾î ÀÖ½À´Ï´Ù. ±× js ÆÄÀÏÀ» ¿­¾î¼­ °ü·Ã ·ÎÁ÷À» ¹Ý¿µ½ÃÅ°´Â °ÍÀÔ´Ï´Ù.
ÃßõÃßõ : 296 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,795
[mySql] ´Ù¾çÇÑ db°Ë»ö ½ºÅ³ ÃÑÁ¤¸® (¶ç¿ö¾²±â ¹«½Ã, ´ÙÁß°Ë»ö, Æ÷ÇԵǴ ´Ü¾î °Ë»ö)
2,794
php sqlÀÎÁ§¼Ç °ø°Ý¸·±â
2,793
[php] SQL ÀÎÁ§¼Ç °ø°Ý
2,792
[PHP] Á¤±ÔÇ¥Çö½ÄÀ» ÀÌ¿ëÇÑ Æ¯¼ö¹®ÀÚ ¼ýÀÚÁ¦°Å
2,791
Á¤±ÔÇ¥Çö½Ä - ÆÐÅÏ º¯°æÀÚ
2,790
PHP ȯ°æº¯¼ö Á¤¸®
2,789
PHP Ŭ·¡½º »ç¿ë¹æ¹ý Á¤¸®
2,788
php¿¡¼­ º¯¼ö°ªÀ» ÇÔ¼öÀ̸§À¸·Î »ç¿ëÇÏ¿© ÇÔ¼ö ½ÇÇàÇÏ´Â ¹æ¹ý
2,787
repaceÀ» ÀÌ¿ëÇÑ Á¤±Ô½Ä ¸ðÀ½
2,786
HTML ÆäÀÌÁö¿¡¼­ ÁÖ¼®À» Á¦°ÅÇÏ´Â Á¤±Ô½Ä(PHP)
2,785
PHP - ¹®ÀÚ¿­¿¡¼­ HTMLÅÂ±× Á¦°Å + Á¤±Ô½Ä
2,784
PHP Á¤±Ô½ÄÀ» È°¿ëÇÑ ÅÂ±× ¹× ƯÁ¤ ¹®ÀÚ¿­ Á¦°Å ¹× ÃßÃâ ¹æ¹ý
2,783
PHP Á¤±Ô½Ä Á¤¸®
2,782
Á¤±Ô½Ä ÆÐÅÏ ¹®¹ý
2,781
[Á¤±ÔÇ¥Çö½Ä]Á¤±ÔÇ¥Çö½Ä Á¤¸®
2,780
fopen ¸·ÇûÀ» ¶§ fsocketopen »ç¿ë¹æ¹ý
2,779
[php]¿øÇÏ´Â ´Ü¾î¸¦ ã¾Æ¼­ ġȯ ÇØÁÖ´Â ¹æ¹ý preg_replace
2,778
PHP + MYSQL ¿¬°á Å×½ºÆ® ¿¹Á¦ (mysqli Ŭ·¡½º¹æ½Ä)
2,777
PHP + MYSQL ¿¬°á Å×½ºÆ® ¿¹Á¦ (pdo ¹æ½Ä)
2,776
PHP + MYSQL ¿¬°á Å×½ºÆ® ¿¹Á¦ (original)
2,775
DB Á¢±Ù ¹× Äõ¸®¹®(insert,select,update,delete)
2,774
[MySQL] Çʵ忡¼­ ƯÁ¤¹®ÀÚ Æ÷ÇÔ ¶Ç´Â Á¦¿ÜÇÑ DB °Ë»ö, LIKE ,NOT
2,773
jQuery ÇÙ½É - ³ëµå ´Ù·ç±â
2,772
jQuery show() / hide() / toggle() »ç¿ë¹ý
2,771
[jQuery] readyÀÇ »ç¿ë¹ý
2,770
[jQuery] À§Ä¡±â¹Ý Selector
2,769
[jQuery] css selector
2,768
document.getElementByTagName()¸¦ jQuery·Î ¹Ù²ãº¸ÀÚ.
2,767
getElementsByClassName¸¦ jQuery·Î ¹Ù²ãº¸ÀÚ.
2,766
getElementById¸¦ jQuery·Î ¹Ù²ãº¸ÀÚ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.