In my experience, one important reason why Jehovah may not immediately answer a prayer is based on Proverbs 27:11. If Jehovah were to answer us immediately, we would never have a chance to prove ourselves wise in waiting and trusting in our God. Also, how could God give a reply to Satan's slander that we only serve him out of selfish interest if he did indeed immediately satisfy our every prayer. Instead, just by our mere patiently waiting, we both prove our loyal love for God and prove Satan a liar.
Beyond the above, consider these parent/child comparisons:
Timing: A child wants sees a new toy and wants it NOW! But the parent has already bought the toy for the child and was planning on giving it to him as a gift a little later. As much as the child may complain and even accuse the parent of not loving them, the complete opposite is true. Likewise, Jehovah in his wisdom knows when it is best to answer a prayer.
Training: A child loves sports. The parent watches from the sidelines as the child fumbles through the experience. The parent wants to come to the rescue of the child but realizes it is good training in learning to endure difficult situations. It also builds confidence and character. Likewise, the training we receive through endurance is mentioned in scripture.