From God is the Gospel:
“Answered prayer is based on Jesus’ priestly intercession for us, and that intercession is based on the blood he shed to remove our sins and release the flood of prayer-answering grace.”
This would be why God does not hear the prayers of non-Christians lest they be prayers of repentance. Jesus’ blood is too precious for God to answer prayer of the merely sincere. All answered prayer is owed to the gospel.
Piper spends some time in James 4, undressing our corrupt motives in prayer. “It’s because we ask God for things to indulge our desires that are not desires for him.”
Often we want money so our lives can be easier and we can take great vacations. I recently had a desire to make a bundle of cash, so I could own a big, home with a big yard so I could adopt children abandoned by their parents. This would reveal the adoptive love of God (Ephesians 1). God may not answer that prayer, because maybe I can’t really be trusted with all that money. Maybe that is a fleeting desire soon to be replaced by big TVs, big cars, lush vacations and cosmetic surgery.
If the people James wrote to had corrupt motives in prayer, we probably do too.
“You would not be honored if I thanked you often for your gifts to me but had no deep and spontaneous regard for you as a person.” That’s what they did, and this is what we do often enough. Our joy is not in God, but in His gifts.
“If gratitude for the gospel is not rooted in the glory of God beneath the gift of God, it is disguised idolatry.”
This is why the Westminster Shorter Catechism, answer #1 reads “Man’s chief end is to glorify God and enjoy Him forever.” But every good gift also comes with a temptation to love it more than Him. It is a struggle to keep our hearts from from idolatry. It’s like trying to keep the weeds out of your lawn- seemingly inevitable.
He wraps up with Augustine (finally) “He loves Thee too little who loves anything together with Thee which he loves not for Thy sake.”