Three of the Gospels agree that there was an incident of this kind. Luke has the presence of mind to lose it.
Luke does have a similar story that connects the Mark version with the John version, though, at Luke 7:36-50. I won't quote it all, but to show that it has elements from both:
36. When one of the Pharisees invited Jesus to have dinner with him, he went to the Pharisee’s house and reclined at the table.
37. A woman in that town who lived a sinful life learned that Jesus was eating at the Pharisee’s house, so she came there with an alabaster jar of perfume.
38. As she stood behind him at his feet weeping, she began to wet his feet with her tears. Then she wiped them with her hair, kissed them and poured perfume on them.
I guess it's possible that it's a completely different incident than the one John talks about, but then it means more than one woman was washing Jesus's feet with her hair. And I don't think it makes it better, tbh.
Incidentally, in the next verses it turns out the Pharisee is called Simon, so there's one more connecting element to Mark there.
Interestingly enough, here it's made the clearest of all versions that it could have been prevented (e.g., he could have stopped her by the time she was washing his feet with her hair) Jesus is just laying back and letting her do that. In fact the Pharisee's objection is precisely that Jesus doesn't react.
And Jesus's answer to the Pharisee also makes it pretty clear that Jesus thinks he's entitled to that:
44. Then he turned toward the woman and said to Simon, “Do you see this woman? I came into your house. You did not give me any water for my feet, but she wet my feet with her tears and wiped them with her hair.
45. You did not give me a kiss, but this woman, from the time I entered, has not stopped kissing my feet.
46. You did not put oil on my head, but she has poured perfume on my feet.
47. Therefore, I tell you, her many sins have been forgiven—as her great love has shown. But whoever has been forgiven little loves little.”
I mean, not only is he okay with it all along, but he actually imputes to his host that he didn't humiliate himself towards Jesus too. He actually imputes to the Pharisee, "
You did not put oil on my head". He's not just ok with having expensive oil put on him, but actually imputes to his host that he didn't.
Also it indicates that it had been going on for a while: "
but this woman, from the time I entered, has not stopped kissing my feet." I mean, it's not just a one off kiss that might have surprised him. But there he's lounging while a woman keeps kissing his feet, and not only he doesn't stop her, he seems to think he's entitled to that kind of show of self-humiliation before him.
Incidentally, it's also funny that he complains that the Pharisee didn't kiss him. I'm surprised that that verse doesn't get slung at the homophobic bible bashers all the time.
The most specific report is the last, John 12: 1-11.
The woman in question is Mary of Bethany, and the location is her family home. She is grateful that Jesus fetched her prematurely buried brother out of his tomb. God only knows what would have happened to poor Lazarus if Jesus hadn't come along.
Duly noted, though for the purpose of trying to reconstruct a plausible historical Jesus, I'd be somewhat wary of an explanation that involves a miracle as a reason. Which really is what John introduces there.
Mark doesn't seem to have heard of any reason why a nameless woman from Bethany (which is a symbolic name too, as it means "house of misery" or "house of the poor". Or in modern vernacular, it happens in Poor Town) gets some expensive perfume and pours it on Jesus's head, much less a miracle. In fact, as Ethnikos said, in Mark this happens in the house of Simon the Leper, whoever that was. There's no mention that he'd gotten raised from the dead too.
Also John changes the story a bit. In John, she pours the oil on Jesus's feet and wipes his feet with her own hair. Which actually makes it a little more wth for me that Jesus would lay back and enjoy such a spectacle of a woman humiliating herself extremely before him.
Plus in Mark it's easier to imagine some ninja woman

who surprised Jesus from behind with that oil pouring, while in John surely Jesus would have noticed that someone is crouching at his feet to the extent where she can wipe his feet with her hair.
The critic is Judas. His outrage at the incident and the unsatisfactory answer Jesus improvises form the rational basis of his cooperation with the authorities soon afterwards. Judas' interest in the poor is portrayed as insincere; he would have stolen the proceeds from selling the oil, according to John.
Again, this is a detail that appears only in John. The original version in Mark, on the contrary, would have more than one person ("Some of those present") find the event indignant.
But ok, given that Judas immediately changes his mind about Jesus, it's quite plausible that he'd be one of those who objected.
I'd add though that John's adding that explanation is interesting, because it basically counters exactly the kind of objection that Ethnikos posted. If Judas thought it had been possible for him to get that money, it indicates that the situation could have been prevented.
Jesus baits his disciples, and anybody else who'll listen to him, throughout the Fourth Gospel. He whines about how he's going to die quite a bit. It's no surprise, then, that he would reach here for a speech based on the dual use of oil, not only for sex but also for death. It's all very French.
To be fair, Jesus repeatedly "prophecises" his own death in all four gospels, not only John. He's more upfront about that and generally being the messiah to strangers in John, as opposed to the "sshhh, don't tell anyone" Jesus of Mark, but to his own disciples... yeah, all four gospels agree about his telling them all over the place that he's the messiah and he's gonna die.
In the bigger picture, a great deal of Jesus' "teaching" consists of him talking his way of tight spots. Judas has him by the short curlies here, since Jesus has gone "off message" big time. The self-serving BS about the poor is quoted from Deuteronomy 15: 11. The Devil isn't the only one who can cite scripture to his own ends.
Ironically, the meaning in context of the original passage is not to flip off the poor, but to be mindful of them always. It is more than possible that Judas knows that. In the story, he doesn't get mad, he gets even.
Agreed.
I don't want to be overly critical of Jesus. I have to admit that if a hot young woman who thought she owed me one approached with a bottle of body oil, then I would be heedless of the poor for a few minutes, too.
Heedless of the poor, maybe. But I'm pretty sure that if anyone did such a gesture of extreme humility before me, I'd go, "wait, seriously, rise, no need to do that," rather than lay back and enjoy. And I don't claim to be the model of good guy and messiah.
Especially in Luke's version, I find it abject that someone would lay back and let a stranger humiliate herself before him for enough time for that conversation to go as it did, and not only try to stop her, but give an answer that indicates he thinks he's entitled to that.
It is interesting to speculate how much world history might be different if, instead of playing the wounded rabbi, Jesus had just said, "Sorry, Jude, I was thinking with the little head there for a while. I'm only human, you know."
I guess we'll never know.