If the mess has soaked through you must pull up the carpet and clean or replace the padding below. This was the problem with my couch, by the way. The neighbor's dog sniffed and marked exactly the place where another canine visitor had hit months earlier, and which I apparently hadn't deodorized well enough. Don't delay clean-ups. When accidents occur, you must clean them up promptly and thoroughly.
Messes are easier to clean when they're fresh, and are less likely to leave a permanent stain.
Don't use ammonia-based cleaners on pet messes. So instead of making the area smell clean, ammonia products make a mess site seem even MORE attractive to your pet. Use products designed for pet messes. Crystal products work well, too, by absorbing fresh messes in a few minutes so you can vacuum them up. You can also make a fairly effective cleaner for a fresh urine accident with water, white vinegar and a gentle soap such as Ivory.