My repeated Ajax call deletes session flash data
I have a Javascript to make an Ajax call it calls my api every 5 seconds to update my user page.
I am returning a view with flash data which it has to keep for the next request but the Ajax call clears it and the next request is not completed.
Is there a way to complete it?
I can think to re-flash on an api call, but that seems weird. Any other way?
Since your ajax call needs access to the session information, you have to load the session, which will count as your access to the flash data. You will need your ajax call to reflash the data.
There is a reflash method on the session that will take care of this for you. You can either call it in the Controller method that handles your ajax call, or better yet, create a new middleware that reflashes session data, and attach the middleware to any route that needs this functionality.
Related
I have an ajax call which is used to perform a task and correspondingly update a table with the progress status.Now i have another ajax call to fetch the status from the table to show the task progress status to the user.The second call gets called repeatedly for every 2 seconds until the task is complete.But i could not show the task progress status to the user as the second ajax call keeps on loading till the response comes for the first ajax call.
I found a similar question in stackoverflow in the following link and it was suggested that it might be due to session lock and that using session_write_close() might work.I tried it and found no success.
Prevent jQuery AJAX call from waiting for previous call to complete
Is there a way to get the response for the second ajax call even while the first ajax call is still processing?
You can controller your Ajax functions flow using deferring concept of jQuery like
var defered = jQuery.Deferred();
function your_function(){
//do something!
defered.reslove()
return defered.promise
}
your_function.then(function(){
//this will not run till your_function is done
})
learn more at https://api.jquery.com/jQuery.Deferred/
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
I started writing with magento. I have to do some ajax request for my own php-script located somewhere in local pull. The questions are:
Where to store such php-scripts and with what address access them from ajax-request?
Just create a Controller that has an action that will handle the AJAX call. So if your module has a route of http://www.yoursite.com/yourscript, and you already have your IndexController, just put another action in there such as ajaxAction(). This action will simple print out the data you want to be consumed, and not render the rest of the page. Then you can point your AJAX call to http://www.yoursite.com/yourscript/index/ajax.
I have logged a user into the app on the site and retrieved their details using EpiTwitter/Twtitter-Async. I then want to process these and others through an ajax call and post a new tweet on success.
Specificially, my problem lies with reusing the cookie, i see they are gettting set but I cannot see how to reuse them in later pages. what function do I call?
Thanks
In the php file that catches the ajax request you can access the cookie information in $_COOKIE. It should automatically be sent with the ajax request.
http://php.net/manual/en/features.cookies.php
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.