refresh xml grid

Hi please? can anyone tell me, How i can call php script from java on the client, get answer from server, for example OK or ERROR, and if OK clear and load grid again ??

I use ajax for it, but he doensn’t wait when script end of work on server (script work about 5sec),
and i can’t get answer from script because java on client side don’t wait this 5 seconds