yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.22k stars 6.93k forks source link

Support ajax in data-method links. #10911

Closed SamMousa closed 8 years ago

SamMousa commented 8 years ago

Currently the framework provides some unobtrusive scripting to make life easier: <a href="/test" data-method="post">Cool post link</a> will post the parent form, or create a new form and post that when the link is clicked. When creating more advanced application, feedback could also arrive through other channels (shared web workers, EventSource, WebSockets, COMET), for those cases the request should be done as AJAX and it's response should throw generic events.

I propose some new values for data-method: ajaxPost and ajaxGet. The logic behind these is as follows:

  1. If the request is successful trigger some to-be-named success event.
  2. If the request is not successful trigger some to-be-named fail event.

Since there is currently no defined behavior for those values the only users that could experience issues are people that have JS that uses the exact same values as mentioned above for the data-method field.

samdark commented 8 years ago

How do you want to handle these events?

SamMousa commented 8 years ago

Assuming you mean the generic events I referred to? Those can just be consumed in javacript:

$(document).trigger(eventName, params);
$(document).on(eventName, function(e, param1, param2) {

});
samdark commented 8 years ago

If you're writing JavaScript for it, why not to implement click handler in the first place? I don't think that's a good idea.