2Chron 18; 1 Kings 22 One can almost hear the voice of James as he might have recalled this OT story.
“you ask and do not receive because you ask wrongly, so you can spend it on your passions.” [James 4:3] So, let’s backtrack to see why.
King Ahab is a wicked king of Israel, yet the righteous king of Judah, Jehoshaphat, has divided allegiances when he chooses to marry Ahab’s daughter. But family is family, and so Jehoshaphat goes to visit his father-in-law. While there, Ahab tests him by asking him to go with him into battle against his enemy. Instantly he answers, of course—but quickly says first, let’s ask a prophet his advice. Ahab scornfully says there is only one prophet of God there, yet interestingly he knows that the godly prophet Micaiah is a truth-teller. Therefore when Micaiah tells him that he will lose in this battle and die, he should have listened. But fools do not listen! But Ahab desires victory over obedience, so he ignores his words. End of story: the words of the godly prophet come true; Ahab is killed in battle.
The moral of the story is don’t ask God for something if you are unwilling to listen and obey.