Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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