"So about three thousand went up; but they were routed by the men of Ai, who killed about thirty-six of them. They chased the Israelites from the city gate as far as the stone quarries and struck them down on the slopes. At this the hearts of the people melted in fear and became like water." NIV translation
Now, we see that all of Israel had forgotten that it was God that gave them the victory over Jericho. They are now back to walking by the flesh and Joshua did not even consult God as to sending the men to Ai. Because of this, the Israelites were soundly defeated and, when the people found out, fear spread throughout the people.
"Then Joshua tore his clothes and fell facedown to the ground before the ark of the Lord, remaining there till evening. The elders of Israel did the same, and sprinkled dust on their heads." NIV translation
Joshua came to his senses and realized that they needed to repent and call on the Lord. He was joined by the other leaders of Israel and this is a reminder that true leaders can admit when they have failed. They had failed by following the flesh and what their eyes saw instead of the Lord.
"And Joshua said, 'Alas, Sovereign Lord, why did you ever bring this people across the Jordan to deliver us into the hands of the Amorites to destroy us? If only we had been content to stay on the other side of the Jordan! Pardon your servant, Lord. What can I say, now that Israel has been routed by its enemies? The Canaanites and the other people of the country will hear about this and they will surround us and wipe out our name from the earth. What then will you do for your own great name?'" NIV translation
Joshua calls out to the Lord with a bunch of pious nonsense. He was right in connecting the fate of the people with the name of God but the rest of it was a "pity party" for them. He went so far as to question the action of God in bringing them into the land. That is what walking in the flesh instead of the Spirit will do to you.