You won't like my answer, but here it is anyway: buy better headphones. The most common point of failure in headphones is the cable, near the 3.5mm jack. From repeated bending, the conductor inside the cable eventually breaks, which is why you need to wiggle the connector to momentarily make it work.
I guess you could repair the cable, by cutting a few inches above the jack and soldering a new one, but it isn't worth it on cheap headphones. So, I suggest you invest in a decent pair of headphones, one with a detachable cable if possible.