Christ had the opportunity to ask this of the woman because his disciples, whom he would have asked for the water, were not there, thus the Evangelist says, His disciples had gone to the town.
Here we might notice three things about Christ. First, his humility, because he was left alone. This is an example to his disciples that they should suppress all pride. Someone might ask what need there was to train the disciples in humility, seeing that they had been but lowly fishermen and tentmakers. Those who say such things should remember that these very fishermen were suddenly made more deserving... of respect than any king, more eloquent than philosophers and orators, and were the intimate companions of the Lord of creation. Persons of this kind, when they are suddenly promoted, ordinarily become proud, not being accustomed to such great honor.
Secondly, note Christ's temperance: for he was so little concerned about food that he did not bring anything to eat. Thirdly, note that he was also left alone on the cross: "I have trodden the wine press alone, and no one of the people was with me" (Is 63:3).
Source: Commentary on John