Code Monkey home page Code Monkey logo

laravel-ajax-redirector's Introduction

laravel-ajax-redirector

A Laravel library for handling AJAX redirects

Author StyleCI Software License Packagist Version Total Downloads

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

composer require superbalist/laravel-ajax-redirector

Register the service provider in app.php

'providers' => [
    Superbalist\AjaxRedirector\AjaxRedirectServiceProvider::class,
]

Usage

In your application, you'll continue to do redirects like you always have.

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"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.