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

jQuery.getScript, JavaScript ÆÄÀÏÀ» ·ÎµåÇÏ°í ½ÇÇà
7³â Àü
°³¿ä : 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 ÆÄÀÏÀ» ¿­¾î¼­ °ü·Ã ·ÎÁ÷À» ¹Ý¿µ½ÃÅ°´Â °ÍÀÔ´Ï´Ù.
ÃßõÃßõ : 288 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
2,885
input ÀÔ·Â ÇÊµå ¾ÕµÚ °ø¹é ½Ç½Ã°£ Á¦°Å
2,884
Placeholder Æ÷Ä¿½º½Ã °¨Ãß±â
2,883
MySQL Áߺ¹µÈ µ¥ÀÌÅ͸¦ »èÁ¦
2,882
MySQL Áߺ¹ µ¥ÀÌÅÍ È®ÀÎ
2,881
sessionStorage.getItem ¿Í sessionStorage.setItem
2,880
Á¦ÀÌÄõ¸® ·£´ýÀ¸·Î ¹è°æ»ö º¯°æ
2,879
preg match¿¡ °üÇÑ Á¤±Ô½Ä
2,878
Stream an audio file with MediaPlayer ¿Àµð¿À ÆÄÀÏ ½ºÆ®¸®¹Ö Çϱâ
2,877
Audio Streaming PHP Code
2,876
PHP $ SERVER ȯ°æ º¯¼ö Á¤¸®
2,875
Vimeo (ºñ¸Þ¿À) API ¸¦ »ç¿ëÇÏ¿© Ç÷¹À̾î ÄÁÆ®·ÑÇϱâ
2,874
iframe »ç¿ë½Ã ÇÏ´Ü¿¡ ¹ß»ýÇÏ´Â °ø¹é Á¦°Å¹æ¹ý
2,873
¾ÆÀÌÇÁ·¹ÀÓ(iframe) Àüüȭ¸é °¡´ÉÇÏ°Ô Çϱâ
2,872
ºÎÆ®½ºÆ®·¦(bootstrapk)¿¡¼­ »ç¿ëÇÏ´Â class¸í Á¤¸®
2,871
ºÎÆ®½ºÆ®·¦ CSS
2,870
Å©·Ò¿¡¼­ ¸¶Áø Á¶Àý
2,869
PHP ÇöÀç ÆäÀÌÁöÀÇ µµ¸ÞÀθíÀ̳ª urlµîÀÇ Á¤º¸ ¾Ë¾Æ¿À±â
2,868
PHP preg match all()
2,867
PHP ·Î À¥ÆäÀÌÁö ±Ü¾î¿À±â ¸ðµç ¹æ¹ý ÃÑÁ¤¸®!
2,866
[PHP] ¿ø°ÝÁö ÆÄÀÏ ÁÖ¼Ò ³ëÃâ ¾ÈÇÏ°í curl·Î ´Ù¿î·Îµå ¹Þ±â
2,865
PHP ÇÔ¼ö Á¤¸®
2,864
¾ÆÀÌÇÁ·¹ÀÓ(iframe) ºñÀ² À¯ÁöÇϸ鼭 Å©±â Á¶ÀýÇÏ´Â ¹æ¹ý
2,863
PHP ¹è¿­¿¡¼­ ¹«ÀÛÀ§·Î Çϳª »Ì¾ÆÁÖ´Â array rand() ÇÔ¼ö
2,862
PHP Á¤±Ô½Ä Á¤¸®
2,861
PHP Á¤±Ô½ÄÀ» È°¿ëÇÑ ÅÂ±× ¹× ƯÁ¤ ¹®ÀÚ¿­ Á¦°Å ¹× ÃßÃâ ¹æ¹ý
2,860
php Å©·Ñ¸µ ¶Ç´Â ÆÄ½Ì ÇÔ¼ö, Á¤±Ô½Ä ¸ðÀ½
2,859
Á¦ÀÌÄõ¸® ±âº» ¸í·É¾î
2,858
À¥ÆäÀÌÁö °¡·Î ¸ðµå¼¼·Î ¸ðµå ÀνÄÇϱâ
2,857
¸ð¹ÙÀÏ À¥ È­¸é °­Á¦ ȸÀü(°¡·Î¸ðµå °íÁ¤)
2,856
[HTML5]¿¡¼­ frameset ´ëü ¹æ¹ý°ú iframe ¼Ó¼º
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.