Codeigniter - How to do work on server, after view file is shown?
What is the best way of spitting out the view file in codeigniter and still doing some work on the server? The situation basically is:
- I have a payPal checkout where user goes to paypal and clicks Pay Now! A set_express_checkout() is called to start things off.
- The user is returned to the Thank You page.
- I have to call a Get_express_checkout_details() and a do_checkout() before showing him the Thank you page and this is 2 calls to a pretty slow payPal server.
My problem is, that when 开发者_高级运维the user clicks on Pay Now! button, he is redirected back to my site but hangs at payPal for at least 5 seconds (while my server makes the 2 requests) before he can se anything. So the question is: Where should I make these two calls so the user doesnt have to wait so long before anything is shown to them?
I think using AJAX request is justwhat youwant. The idea is the following:
- Output your page to client not performing any paypal requests
- Create additional page/method that only performs paypal request and outputs data as
json
- On the outputted page place AJAX call to that new page
- Process the response to know, if the request was successful.
For ajax calls youmight want to have a look at jQuery.ajax. Most convenient way to output json
data from PHP is using json_encode
PHP function.
You could enable hooks and use the 'post_system' hook to make your two calls to the slow server. See http://codeigniter.com/user_guide/general/hooks.html for more information.
However this will leave you with no easy way of showing any result of the two calls.
精彩评论