[I wrote my first version of this several years ago, when my 5 year old daughter had to have a colonoscopy to check for stomach problems. Thank Gd, she's fine.]
Bargaining is an automatic reaction to loss, as described by Elisabeth Kubler-Ross in her famous formulation of the stages of grief. Someone takes ill, and at some point he starts to think about what he could do differently, how he could improve, such that he would ‘deserve’ to escape this grief.
For the non-theist the poker chips to be ante'd may include a better diet, dropping smoking, going to the gym, or perhaps creating a stronger positive karma - even after the cards have been dealt.
For the theist, the options include religious improvement: I’ll give more tzedakah, I’ll learn more Torah, I’ll go to minyan.
The semi-conscious theology is that the better I do, the less I’ll ‘deserve’ the loss, and therefore the loss will be reversed.
I have long been troubled by this religious reaction, though. Yes, I say a מי שברך (prayer for the ill) and certainly recite the normal prayers and psalms. No, I can't deny ותשובה ותפלה וצדקה מעבירין את רוע הגזרה, that repentance, prayer and charity can save us from harm. And we do have a concept of נדרים בשעת צרה, vowing to Gd in times of need (see Tosafos Chullin 2b). But even still, I can’t bring myself to say, “I’ll change my life if only You’ll take the bad thing away.”
Part of that reluctance is because this mitzvos-for-prizes approach feels like it cheapens religion; mitzvos demonstrate loyalty, they aren’t bribes. Yes, I know the Gemara (Pesachim 8a) that “One who says ‘I give this coin to tzedakah that my son may live’ is a צדיק גמור, fully righteous.” And I understand why that’s true. But all the same, my heart is with Antigonus of Socho (Avos 1:3); pledging mitzvos for rewards feels wrong.
Another part of my reluctance is that the whole bargain is just so presumptuous. If I learn more Torah, then my relative should live? Rabbi Yochanan lost ten children (Berachos 5b); is my extra learning going to make me more worthy than Rabbi Yochanan? It’s like when people talk about having been saved from a disaster by a G-d-driven coincidence - what about all of those people who weren’t saved, were they not as worthy as you?
So I just keep on doing the regular davening, dedicate a shiur for a refuah shleimah perhaps, and hope for the best.