CI Ajax Calling Issue - php

I have controller named "test.php". I have also written the ajax calling functions in this page as well. Like for checking data, uploading the image etc.
Problem is when ever i call any of the ajax function , and do logout after it (successful or UN-sucessfull result of ajax), And then login again, then it transfer me to same ajax function which i called before logging out, instead of index function. Below are steps that i follow.
Call ajax function "test/ajax_1_chk" to check user data.
Logout the user.
login Again with any user.
it will redirect to "test/ajax_1_chk" , but instead ti should go to "test/index". this happens only first time.
I applied path in it. But does not work all the time.
Can any one guide me in this.
Thanks in Advance

Related

PHP redirection with post values

Is it possible to redirect user to external server without using:
header('Location:address.com?var=1');
or
HTML form with JS auto submit
Seems really simple but can't figure it out. I do not want to use GET, I would rather send it via headers/post if possible.
Making ajax request is slowing it down and I believe there should be some kind of solution in pure PHP.
CURL is not an option as I want to go to that link with posted data.
Cheers
You can do this using this method session_set_cookie_params(). It is used to transfer data from 1 url to another url using session. To get the result you have to write this function before every session_start().
session_set_cookie_param();
#session_start();

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.

How to authenticate a username & password of the user without redirecting to another page?

I want to authenticate the user without refreshing/redirecting to another webpage. If the username and password combination is incorrect, I want to show a message there itself without redirecting/refreshing the page. And if the username and password combination is correct, then I want the page to redirect to home page. An example is given below, the error message appeared without refreshing the page. Can anyone help me in get this thing done? Thanks!
Example:
Use Ajax! the idea is to use XmlHttpRequest objects to send requests back to the server and get response .
Google for PHP ajax login:
http://www.roseindia.net/ajax/ajaxlogin/ajax-login-program.shtml
http://evolt.org/ajax_login_system
Using jQuery:
http://www.chazzuka.com/php-ajax-login-form-using-jquery-82/
http://roshanbh.com.np/2008/04/ajax-login-validation-php-jquery.html
http://ajaxmint.com/2009/12/php-ajax-login-form-using-jquery/
You can do this with the help of making ajax request to your php file, which will then execute your username and password and return true or fase or Other information about request....
This is the simplest way to do something on same page.
You have at least two choices:
AJAX request (as others suggest), that will submit the form and make proper action depending on whether this was success (eg. load private data) or error (eg. display information about incorrect username/password),
IFRAME containing login form, that will reload itself, not the whole window (and eventually make some action or execute some script, depending on what you need),
Use AJAX! With it, user doesn't need to reload page to communicate with server.

PHP Render/Redirect AJAX Call

I am working on a PHP application and missing some of the functionality that Rails has. I currently have an AJAX form that when submitted accesses my_page_save_ajax.php. After I process the form and save it, I would like to redirect the AJAX call to either my_page_show_ajax.php if successful or back to my_page_edit_ajax.php if an error occurred.
I have thought about using an include my_page_..._ajax.php, but I have always had problems with the file paths and PHP not knowing what to render. Not to mention, both of those files include utilities.php and I'm afraid there might be conflicts. I guess I could use include_once but it seems like there might be a more elegant solution.
How can I process the form and return the output of another PHP page?
Thanks very much!
If you redirect the AJAX response, it won't actually redirect the user's browser anywhere. It will simply affect what data comes back through the AJAX call. This may be a good instance to simply not use AJAX, since it sounds like the user may go on only one of two paths.
If you still want to redirect the user, you could send back a javascript snippet which redirects the user via setting window.location

How can I redirect after Facebook.streamPublish() has completed?

I have an application which will post a message on a friends wall using the Facebook.streamPublish() method, and this works perfectly. However, I want to also be able to save details about this post in my database.
All the information that needs to be stored is placed into hidden form fields and are all in place once the message has been sent, so I figure that all I need to do is redirect to a php file which will take this information, save it into the database and then redirect back to the main page.
The streamPublish call is:
Facebook.streamPublish(\'\', attachment, null, params.ids[curFriend]);
which I can follow with form.submit() which will cause the redirect to happen, but this submit() function gets called instantly, and doesn't wait for the streamPublish() popup to load, be used, and the action to be completed. How can I make my form.submit() not be called until the user has hit the 'publish' button in the popup which occurs?
StreamPublish also takes an optional callback function - http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.streamPublish . Try setting your submit() function as the callback and it should get called once the user cancels the dialog or publishes it
I've not used the streampublish() function or the FB API, but I can guarantee that this is because the streampublish is handled by an ajax call, which is thus handled separately from the normal JS code chronology. So any code that should be executed when the ajax has reached a specific state needs to be added to the ajax statehandler, which the FB API may or may not give you access to.

Categories