gregschmit / recurring_select

A gem for adding selectors for setting recurring events.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting jQuery AJAX dataType globally can break select dialog

styrmis opened this issue · comments

Firstly thank you for open sourcing this, it's a fantastically useful component.

In my app I set the dataType of all jQuery AJAX requests to be JSON as that is what I am using throughout.

This breaks recurring_select however as the plain text / HTML response that the translation API returns (which is of course not valid JSON) will cause the error callback to be executed (in https://github.com/GetJobber/recurring_select/blob/master/app/assets/javascripts/recurring_select_dialog.js.coffee.erb#L162) as by default jQuery will now be requesting a JSON response.

I believe the simplest fix here would be to explicitly set the dataType attribute of the POST request to HTML; this would ensure that the dialog will work correctly in environments where the default response type has been changed.

Up until this point I had no idea that recurring_select made AJAX requests, perhaps this could be mentioned briefly in the README?

Also when the requests fail (which will happen at some point) then the dialog just freezes due to the lack of an error-handling callback for the POST request. As such it may be a good idea to add in an error callback to make the component more robust. If I add this then I'll submit a PR for it but for now in my own branch of recurring_select I am simply making the dataType setting explicit in the POST request.