My RAZR M was having a lot of problems connecting to WiFi when I first got it. But it was only mine, it connected to everyone else's with no problem. I had to change my router from WAP to WEP. Its less security, but it connected immediately. I can't tell you why, I just know it works. I think I'll have to get a new router because I'm nervous about the security. Not sure if this will help you or not, but it worked for me.
I had that happen whenever I was on the other side of the house from my router, but fixed it in my wifi settings. When on the wifi screen in settings I hit the menu button (three dots on the bottom right). I choose "advanced". The setting for "Avoid poor connections" was checked by default. I have never had a problem with it since I unchecked that setting.