In order to perform safe and natural interactions with humans, robots are required to adjust their motions quickly according to human behaviors. Performing the complex calculation and updating the trajectories in real-time is a particular challenge. In this paper, we present a real-time optimization-based trajectory planning method for serial robots. We encode the trajectory planning problem into a series of optimization problems. To solve the high-dimensional complex non-linear optimization problems in real-time, we provide a joint-decoupling method that transforms the original joint-coupled optimization problem into multiple joint-independent optimization problems, with much lower computational complexity. We implement and validate our method in a specific human-robot interaction case. Experimental results show that the computational feasibility and efficiency of optimization solution were greatly improved by the joint-decoupling transformation. Smooth, safe, and rapid motion of the robot was generated in real-time, establishing a basis for safe and reactive human-robot interactions.