Buck gives John Thornton such unstinting loyalty because John treats him with kindness, compassion, and consideration. Ever since he was dognapped from the ranch, Buck's been treated appallingly by every human with whom he's ever come into contact. But John's different; John actually cares. After he rescues Buck from Charley and Hal, he slowly nurses him back to health, showing great tenderness and even love towards the stricken hound.
Soon the two become inseparable companions. John never loses an opportunity to show his affection for Buck by putting his head next to his. Buck appreciates John's lavish attention and thrives under the tutelage of his new master. Not only does Buck become more trusting of people thanks to John, he also grows stronger, both physically and mentally, better able to take whatever life on the trail has to throw at him.