Skip to content

Instantly share code, notes, and snippets.

@rjvdw
Created August 30, 2016 08:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjvdw/f8dd024ce141def8a48604e4aa6afdc6 to your computer and use it in GitHub Desktop.
Save rjvdw/f8dd024ce141def8a48604e4aa6afdc6 to your computer and use it in GitHub Desktop.
JSONP Example With jQuery And Laravel

JSONP Example With jQuery And Laravel

javascript

$.ajax({ url: '/my-pretty-url', dataType: 'jsonP' })
  .done(function (data, textStatus, jqXHR) {
    console.log(data)
  })
  .fail(function (jqXHR, textStatus, err) {
    throw(err)
  })

php

Route::get('/my-pretty-url', function (\Illuminate\Http\Request $request) {
  return response()
    ->json([
      'foo' => 0,
      'bar' => [
        'baz' => 1,
        'qux' => [ 0, 1, 2 ],
      ],
    ])
    ->setCallback($request->input('callback'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment