1 John 3:22: "22 And whatsoever we ask, we receive of him, because we keep his commandments, and do those things that are pleasing in his sight."
The person who walks in the kind of obedience and love John speaks of will also experience answered prayer. This is not because their love and obedience has earned them what they ask, but their love and obedience come from fellowship - the key to answered prayer. John seems to be quoting Jesus' idea from John 15:7 - "If you abide in Me, and My words abide in you, you will ask what you desire, and it shall be done for you."
Keeping God's commandments is important to answered prayer. But we should make a distinction between the prayer of the man who is saved, and the cry of the heart seeking mercy from God in Jesus. For the sinner who comes to Jesus in prayer, seeking mercy, the only requirement is sincerity of heart. God does not demand our obedience before He saves us. The key to prayer is being in such close fellowship with God that we ask for the things that are on His heart; we take up His agenda with our requests and intercession. The spirit of true prayer is Thy will be done, not My will be done - we turn to prayer to call into action what God desires; even knowing that some of the things God desires will directly and personally benefit us.
The person who is in fellowship with God will want to do those things that are pleasing in His sight. We should have hearts that just want to please the Lord in everything that we do. It is sobering to look at our lives and see how much we do to please ourselves and how much we do to please the Lord. We shouldn't think that the two are opposites; God is glorified when we enjoy His goodness and His good things. Yet, the godly life will have special focus on just pleasing God, even if it doesn't particularly please us at the moment.