Prime Minister Julia Gillard has made a surprise visit to Afghanistan, where she met with Australian troops.