I don't think you will have any problem buying the ticket in Dubai.
The thing that you need to check is which documents you will need to have when you initially fly to Dubai (before you have purchased the ticket to London). For example, when you check-in for your flight to Dubai, your airline may ask you for proof that will be leaving the UAE within the validity period of your visa. Immigration at Dubai may also ask for the same proof.
I don't know the answer to this myself, so you will need to check it with the airline / consulate first. Then you can decide whether it is OK to buy the ticket to London when you are in Dubai, or whether you will need to buy it before you get to Dubai.