Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add postAjax() to Html Builder#45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
yajra merged 3 commits intoyajra:3.0fromElfSundae:post-ajax
Dec 15, 2017
Merged

Conversation

@ElfSundae
Copy link
Contributor

As@herzcthu said on#13 (comment) ,minifiedAjax does not help for a "very big" table.

I think POST ajax is common as well as GET, so I'd like to add a new methodpostAjax() to theHtml\Builder, andpostAjax() has the same API asajax().

$builder->postAjax();

equals:

$builder->ajax(['type' =>'POST','headers' => ['X-CSRF-TOKEN' =>'xxxxxx',    ],]);
  • Excepttype andmethod, any other options will be merged into the finalajax parameter, users are free to set any options forajax.
  • Using an empty string forurl is unnecessary, so I did not fill the defaulturl value. If there is a reason to provide a default url, I will add it.
  • AddingX-CSRF-TOKEN header is a safe way to handle CSRF protection. It does not touch/careajax.data,ajax.beforeSend,jQuery.ajaxPrefilter,jQuery.ajaxSetup, even existingajax.headers.X-CSRF-TOKEN.

yajra, nasatome, and codetestmg reacted with thumbs up emoji
@yajra
Copy link
Owner

Nice idea on adding the token header. The PR looks good but will some actual test within the week. Thanks!

I think we should also note that there is an implication here on the routes. If you are using resource controller, then the request would go to the store method.

@ElfSundae
Copy link
ContributorAuthor

@yajra Yeah, you are right, thanks for reminding. I did not notice resource controllers as I use my custom resource routes&controller instead of Laravel built-inRoute::resource().

Adding a POST route to index may be a workaround?

Route::post('users','UserController@index');Route::resource('users','UserController', ['except' =>'store']);

I know it is not an elegant solution, I am not familiar with Laravel resource controller...

@ElfSundae
Copy link
ContributorAuthor

Another solution: setX-HTTP-Method-Override HTTP header toGET, withPOST Ajax method. And we don't need to set CSRF token.

- if (app()->bound('session') && $token = app('session')->token()) {-     $attributes = Arr::add($attributes, 'headers.X-CSRF-TOKEN', $token);- }+ Arr::set($attributes, 'headers.X-HTTP-Method-Override', 'GET');

But we should note that usingpostAjax() does not mean your route method should be POST as well, contrarily, you need to register your route as GET. is this a problem?

@ElfSundae
Copy link
ContributorAuthor

Another solution: Remove parameters forpostAjax(), and thepostAjax() just acts "Ajax via POST":

$builder->ajax(...)->postAjax();

Or maybe better to do this by changingBuilder::ajax() method:

publicfunction ajax($attributes ='',$post =false)

I will submit a new PR for this.

@ElfSundaeElfSundae reopened thisDec 15, 2017
@yajrayajra merged commitebba497 intoyajra:3.0Dec 15, 2017
@yajra
Copy link
Owner

Released on v3.3.0 🎊 🚀

@ElfSundaeElfSundae deleted the post-ajax branchDecember 15, 2017 16:37
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@ElfSundae@yajra

[8]ページ先頭

©2009-2025 Movatter.jp