We develop a new technique to mathematically analyze and numerically simulate the weak periodic solution to a class of semilinear periodic parabolic equations with discontinuous coefficients. We reformulate our problem into a minimization problem via a least-squares cost function. By using variational calculus theory, we establish the existence of an optimal solution and based on the Lagrangian method, we calculate the derivative of our cost function. To illustrate the validity and efficiency of our proposed method, we present some numerical examples with different periods of time and diverse choices of discontinuous coefficients.