问题
I have a nightmare of a Laravel 4 issue.
Anytime and every single time an AJAX POST is made to the server in the app, it immediately logs the user you of the system! This is horrible and impossible to debug ti seems
Does anyone have any ideas for a solution?
Below are some examples of the AJAX request being made...
$.ajax({
type: 'post',
url: '/orders/orderboards/order/add-item-comment',
data: 'order_item_id=' + order_item_id+'&name='+name+'&body='+body+'&user_id='+user_id,
success: function(result) {
if(result.success){
console.log('SUCCESS AJAX Comment created: ');
working = false;
$(result.html).hide().insertBefore('#addCommentContainer').slideDown();
$('#body').val('');
}else{
console.log('FAILURE AJAX did not save comment:');
}
}
});
I also use the jQuery library X-Editable on some fields of my app which turns fields into edit in place and it handles all the AJAX side of those posts as well.
I can use an AJAX request to load data without issue, it is just when a POST is made to create or update data that you are logged out.
UPDATE
It seems anytime an AJAX request is made to server it is resetting the laravel_session
cookie value. I am not sure what would cause this.
I have noticed in the past if I turn on the config debugging option then each request also resets this value and logs you out. It seems AJAX request also make this behavior happen =(
Any ideas for a solution?
回答1:
This was a very super strange issue which I still do not know the reasoning for it however I do know the cause now...
My JavaScript app made an AJAX request to build the content of a Modal window. In this generated HTML, it made a request to get a Gravatar image and when the image was not a correct URL to a real gravatar image, it forced my user to be instantly logged out of my Laravel 4 app.
I have no idea why that would do anything my my server. Would love to hear some reasoning?
来源:https://stackoverflow.com/questions/31704786/laravel-4-app-logs-user-out-anytime-an-ajax-post-is-made