CIC 2737 “You ask and do not receive, because you ask wrongly, to spend it on your passions.”1 If we ask with a divided heart, we are “adulterers”;2 God cannot answer us, for he desires our well-being, our life. “Or do you suppose that it is in vain that the scripture says, ‘He yearns jealously over the spirit which he has made to dwell in us?’”3 That our God is “jealous” for us is the sign of how true his love is. If we enter into the desire of his Spirit, we shall be heard.
Do not be troubled if you do not immediately receive from God what you ask him; for he desires to do something even greater for you, while you cling to him in prayer.4
God wills that our desire should be exercised in prayer, that we may be able to receive what he is prepared to give.5

1 Jas 4:3; cf. the whole context: Jas 4:1-10; 1:5-8; 5:16.
2 Jas 4:4.
3 Jas 4:5.
4 Evagrius Ponticus, De oratione 34: PG 79, 1173.
5 St. Augustine, Ep. 130, 8, 17: PL 33, 500.