Saturday, 7 December 2013

Javascript and Jquery


http://www.learningjquery.com/2006/09/introducing-document-ready

   


JQUERY:
http://jqueryui.com/demos/
http://try.jquery.com/levels/1/challenges/3
http://coding.smashingmagazine.com/2012/05/31/50-jquery-function-demos-for-aspiring-web-developers/

========================
Simple Ajax call
-----------------
Note: Unable to call $(this) inside ajax so use local variable to access

  $('.make_fav').click(function(){
    var v_id=$(this).attr('id');
    var th = this  // create local var for THIS
    $.ajax({
        dataType: 'json',  // not jsonp
        url: "/favo",
        type: "get",
        data: { id : v_id }, // passing argument to the action
        success: function(response) {
          console.log(response.active)      // based on response change the class
            if (response.active==false){
              $(th).addClass('fav_ajax')
              $(th).removeClass('unfav_ajax')
            }else{
              $(th).addClass('unfav_ajax')
              $(th).removeClass('fav_ajax')
            }
        }
    });

  })
===========================
=>What is prototype property in javascript?
To add new attribute to an object
object.prototype.name=value
ex: user.prototype.age = 28  #when there is no age.

=============

No comments:

Post a Comment