Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Pass all data vars via AJAX calls #60

Open
patrickheeney opened this issue Nov 1, 2013 · 5 comments
Open

[Proposal] Pass all data vars via AJAX calls #60

patrickheeney opened this issue Nov 1, 2013 · 5 comments

Comments

@patrickheeney
Copy link

Instead of having to explicitly create a data-data="var1:1,var2:#var2" attribute, wouldn't it be better to loop through all data variables and pass them into the ajax calls.

For example on the current version:

<a href="#" class="btn btn-default ajax" data-method="post" data-replace-inner="#grid" data-page="1" data-data="action:page,page:1,grid_state:#grid_state"><i class="icon-chevron-left"></i></a>

Could be changed to:

<a href="#" class="btn btn-default ajax" data-method="post" data-replace-inner="#grid" data-page="1" data-action="page" data-gridstate="#grid_state"><i class="icon-chevron-left"></i></a>

I know it doesn't look like much but the benefits are great. For example in the first one I have to declare data-page="1" in addition to adding it to the data-data="" because I use some javascript to manipulate the page using the data-page attribute. However I also need to pass it to the ajax request to use it server side. Another benefit is that we gain access to all the existing functionality such as knowing the method (get or post) to check for variables, what partials we are replacing, etc.

It could be made backwards compat by checking for data-data and using that else passing all data attributes.

@paltman
Copy link
Contributor

paltman commented Nov 7, 2013

@patrickheeney Thank you for you proposal. I have actually been meaning to kill data-data in favor of doing a data-json for the same functionality. So that instead of inventing a new format, we can just use a standard. As far as passing all data- attributes I'd rather not as that means then the server needs to parse through and filter out what it doesn't want. While that might not be a big deal, it also limits the data to be a single dimension/flat.

@paltman paltman closed this as completed Nov 7, 2013
@patrickheeney
Copy link
Author

@paltman Im not sure we are on the same page. How is the server filtering out what it doesnt want when its all passed as POST params. In most applications you simply Input::get('page') or Input::all() - $_POST['page'] or $_POST if you are kicking it old school. You open up a lot of new possibilities by including all data attributes. You don't have to loop through and do any filtering?

Secondly, how would the data be flat? You can accomplish all of the same things as you do now the only difference is instead of cramming all your data into data-json you can decouple that logic and reuse it in individual data attributes.

I don't see how

data-json="action:page,page:1,grid_state:#grid_state"

Is a nicer syntax and more robust then:

data-action="page" data-page="1" data-grid_state="#grid_state"

You are essentially inventing your own custom data attribute format when you can leverage the power of what already exists.

@paltman
Copy link
Contributor

paltman commented Nov 7, 2013

@patrickheeney I wanted to get away from my own invested data format and instead just use JSON. By getting replacing data-data with data-json I did not just mean replacing the name of the attribute but also mean that the contents of the attribute is just JSON, which means it would allow for nesting complex data structures.

@patrickheeney
Copy link
Author

@paltman Sounds interesting but by allowing complex nested data structures are you going to loop through the entire json data structure to detect if they used #attribute_id and replace the value with $(attribute).val() ? I can't think of a use case where the data structure would need to be more complex then key/value pair when passing as post params via ajax. It seems kinda hacky as well: http://stackoverflow.com/questions/15838593/is-it-bad-to-add-json-on-html-data-attribute

@paltman
Copy link
Contributor

paltman commented Nov 8, 2013

@patrickheeney you have given me some things to think about. let me stew on them a bit. thanks!

@paltman paltman reopened this Nov 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants