Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/superbalist/laravel-ajax-redirector
A Laravel library for handling AJAX redirects
https://github.com/superbalist/laravel-ajax-redirector
ajax handling-ajax-redirects laravel laravel-ajax-redirector laravel5 laravel5-package php superbalist
Last synced: 2 months ago
JSON representation
A Laravel library for handling AJAX redirects
- Host: GitHub
- URL: https://github.com/superbalist/laravel-ajax-redirector
- Owner: Superbalist
- License: mit
- Created: 2016-07-08T12:43:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-06-29T02:15:55.000Z (over 1 year ago)
- Last Synced: 2024-04-25T18:21:11.453Z (8 months ago)
- Topics: ajax, handling-ajax-redirects, laravel, laravel-ajax-redirector, laravel5, laravel5-package, php, superbalist
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 33
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# laravel-ajax-redirector
A Laravel library for handling AJAX redirects
[![Author](http://img.shields.io/badge/[email protected]?style=flat-square)](https://twitter.com/superbalist)
[![StyleCI](https://styleci.io/repos/62887913/shield?branch=master)](https://styleci.io/repos/62887913)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Packagist Version](https://img.shields.io/packagist/v/superbalist/laravel-ajax-redirector.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel-ajax-redirector)
[![Total Downloads](https://img.shields.io/packagist/dt/superbalist/laravel-ajax-redirector.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel-ajax-redirector)This package changes the redirect response for AJAX calls from 301 or 302 to a 278 JSON response. XHR requests follow
redirects which in a lot of cases, isn't the intention. In most cases, the intention is for the browser to redirect
the client to the intended page.For **Laravel 4**, please use version 1.0.0.
For **Laravel 5**, please use version 2.0.0+
## Installation
```bash
composer require superbalist/laravel-ajax-redirector
```Register the service provider in app.php
```php
'providers' => [
Superbalist\AjaxRedirector\AjaxRedirectServiceProvider::class,
]
```## Usage
In your application, you'll continue to do redirects like you always have.
```php
return redirect()->to('/test');
```In javascript, you'll need to watch for AJAX calls which result in HTTP 278 responses and do a client side redirect
using eg: window.location.replace(json.redirect_url);With jQuery, this can be done using a Global AJAX Event Handler.
With AngularJS, this can be done using a $http interceptor.
The response from the server will look something like:
```
HTTP/1.1 278 unknown status
Content-Type: application/json{"redirect_url":"http:\/\/your.site.com\/test"}
```