There are many (3-5?) buses a day from [wiki=287d0c92e2c4a9390888a93ed0b03fe9]Agadir[/wiki] to El Jadida.
From the north, there are also buses (howmany??? 2?) a day all the way from Rabat, through Casablanca.
Many buses arrive at night. You are likely to find your hostel or campsite closed at 3:30am. If you have sleeping bags or a tent ground sheet, sleeping on the beach is possible. You may wake up damp from the salt spray though.
ONCF [http://www.oncf.ma/scripts/horaires1.asp] trains depart every 2 hours from Casablanca Port and Casablanca Voyageurs train stations. The trip is around 1 hour, 30 minutes.