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

Fix Ajax error of URL too long#46

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

Closed
ElfSundae wants to merge2 commits intoyajra:3.0fromElfSundae:ajax
Closed

Conversation

@ElfSundae
Copy link
Contributor

@ElfSundaeElfSundae commentedNov 28, 2017
edited
Loading

Ref PR#13#45 , issueyajra/laravel-datatables#348

This PR adds a POST option toajax() method for Html Builder, to make Ajax request to: sending via POST, handle via GET as usual.

Usage:

$builder->ajax('url',true);$builder->ajax(true);

--Updated --

You can also useminifiedAjax at the same time:

$builder()->minifiedAjax()->ajax(true)

@ElfSundae
Copy link
ContributorAuthor

BTW, in my opinion, the defaultajax parameter can be removed as it is optional for Datatables.
And the$attributes ofajax() should not be optional, if user wants to setup ajax parameter, he must provide ajax attributes.
Insignificant things, don't matter.

ElfSundae added a commit to ElfSundae/laravel-datatables that referenced this pull requestDec 7, 2017
@ElfSundae
Copy link
ContributorAuthor

@yajra What do you think?

@yajra
Copy link
Owner

Sorry for late reply, the header method override looks good. Does this mean that we still be using the same route for dataTables and it will not be redirected to store on resource controller? Will try to test this asap. Thanks!

@ElfSundae
Copy link
ContributorAuthor

Yes, no need to change dataTables routes. Just passtrue toajax() method, "URL is too long" will gone.

Laravel determines request method viarequest()->method() actuallySymfonyRequest::getMethod() which handlesX-HTTP-Method-Override header well, e.g.route matching,VerifyCsrfToken.

@yajra
Copy link
Owner

yajra commentedDec 15, 2017
edited
Loading

@ElfSundae this seems to work but needs some modification. IMO, we should not change theajax function and instead promote thepostAjax() to a public method. This is how I tested it:

/**     * Set ajax method to POST, X-HTTP-Method-Override header to GET.     *     * @param  string|array  $attributes     * @return array     */publicfunctionpostAjax($attributes ='')    {if (!is_array($attributes)) {$attributes = ['url' => (string)$attributes];        }        unset($attributes['method']);        Arr::set($attributes,'type','POST');        Arr::set($attributes,'headers.X-HTTP-Method-Override','GET');$this->ajax =$attributes;return$this;    }

UsersDataTable:

publicfunctionhtml()    {return$this->builder()                    ->columns([...])                    ->postAjax()                    ->parameters([...]);    }

Loved the trick you pulled on method override ❤️

* @return $this
*/
publicfunctionajax($attributes ='')
publicfunctionajax($attributes ='',$post =false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Lets keep theajax function as is and promotepostAjax to public api.

@ElfSundae
Copy link
ContributorAuthor

That is what I did in the previous PR#45 , a newpostAjax method.
What I was thinking in this PR is users can simply fix "URL is too long" by just add atrue to their existingajax() or using POST method together withminifiedAjax().

A newpostAjax seems more reasonable, I will commit it later.

So we now have three standalone ways to configure Ajax params:

  • ajax : accepts any dataTables Ajax params
  • minifiedAjax : Setup Ajax with minified URL and GET method, accepts customurl ordata
  • postAjax : Setup Ajax to send via POST (handle it from GET yet), accepts any dataTables Ajax params

@ElfSundae
Copy link
ContributorAuthor

Done in#45

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

Reviewers

@yajrayajrayajra requested changes

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