MVC3中提供了帶有jQuery的不顯眼JavaScript。但是,如何使用不顯眼的Javascript ajax和mootools?使用mootools的不顯眼的JavaScript ajax?
0
A
回答
1
是的,這是微不足道的事情。看看最近發佈的http://mootools.net/blog/2011/12/20/mootools-behavior/,我認爲它支持它。
我在我的Modal.BootStrap(查看github上的鏈接,鏈接的鏈接)中使用了這種方法,它使用數據屬性從ajax資源中獲取數據,雖然不完全相同,但它肯定是一個開始。
我只花了10分鐘,使這個,這是一個良好的開端:
http://jsfiddle.net/dimitar/zYLtQ/
(function() {
var ajaxify = this.ajaxify = new Class({
Implements: [Options,Events],
options: {
mask: "form[data-ajax=true]",
props: {
ajaxLoading: "data-ajax-loading",
ajaxMode: "data-ajax-mode",
ajaxUpdate: "data-ajax-update",
ajaxSuccessEvent: "data-event-success"
}
},
initialize: function(options) {
this.setOptions(options);
this.elements = document.getElements(this.options.mask);
this.attachEvents();
},
attachEvents: function() {
this.elements.each(function(form) {
var props = {};
Object.each(this.options.props, function(value, key) {
props[key] = form.get(value) || "";
});
form.store("props", props);
form.addEvent("submit", this.handleSubmit.bind(this));
}, this);
},
handleSubmit: function(e) {
e && e.stop && e.stop();
var form = e.target, props = form.retrieve("props"), self = this;
var updateTarget = document.getElement(props.ajaxUpdate);
new Request({
url: form.get("action"),
data: form,
onRequest: function() {
if (props.ajaxLoading) {
var loading = document.getElement(props.ajaxLoading);
if (loading && updateTarget) {
updateTarget.set("html", loading.get("html"));
}
}
},
onSuccess: function() {
if (!updateTarget)
return;
if(props.ajaxMode != 'append') {
updateTarget.set("html", this.response.text);
}
else {
updateTarget.adopt(new Element("div", { html: this.response.text }));
}
if (props.ajaxSuccessEvent)
self.fireEvent(props.ajaxSuccessEvent, this.response);
}
}).send();
}
});
})();
new ajaxify({
onContactFormSuccess: function(responseObj) {
console.log(responseObj.text);
alert("we are done.");
}
});
作品具有的DOM:
<form action="/echo/html/" data-ajax="true" data-ajax-loading="#loading" data-ajax-mode="replace" data-ajax-update="#update" data-event-success="contactFormSuccess" method="post">
<input name="delay" value="4" type="hidden" />
<input name="html" value="Thanks for your submission, this is the jsfiddle testing response" type="hidden" />
<input name="name" placeholder="your name" />
<button>submit</button>
</form>
<div id="update">The update will go here.</div>
<div id="loading">loading...</div>
,你應該能夠建立對。在重構時,我會將請求事件移動到他們自己的方法中,並添加更多的校樣等,但它很好。我不知道所有的mvc,但是缺少的一件事是表單驗證事件。我還添加了一個自定義事件,因此您的ajaxifier實例可以執行特定於該窗體的操作(請參閱data-event-success="contactFormSuccess"
)
此外,如果未隱式指定,則可以使用默認請求選項,甚至可以創建什麼請求對象 - Request.HTML,Request.JSON等。像onRequest,spinners等事件也是可行的......我認爲你只需要通過mvc提供的選項和構建它們來開始。
Confirm data-ajax-confirm
HttpMethod data-ajax-method
InsertionMode data-ajax-mode *
LoadingElementDuration data-ajax-loading-duration **
LoadingElementId data-ajax-loading
OnBegin data-ajax-begin
OnComplete data-ajax-complete
OnFailure data-ajax-failure
OnSuccess data-ajax-success
UpdateTargetId data-ajax-update
Url data-ajax-url
相關問題
- 1. 使用不顯眼的AJAX
- 2. Rails3 - 使用Kaminari + AJAX +不顯眼的排序和分頁javascript
- 3. 實現不顯眼的Javascript
- 4. Ajax調用後執行不顯眼的Javascript
- 5. 使用mootools不工作的Ajax請求
- 6. 不顯眼的javascript痛點要小心
- 7. 使用參數實現不顯眼的Javascript
- 8. 用於局部視圖的不顯眼的Ajax表單
- 9. Jquery的不顯眼如何
- 10. 使用Ajax渲染部分視圖不顯眼
- 11. Rails的不顯眼的ajax:失敗事件不觸發
- 12. 停止以前不顯眼的Ajax調用
- 13. 使用MVC 3整個模型的客戶端驗證(不顯眼的ajax)
- 14. 用Cucumber測試JavaScript的不顯眼的方式?
- 15. 如何在rails中使用jquery編寫不顯眼的Ajax調用
- 16. Rails:當JavaScript關閉時不顯眼DELETE
- 17. ASP.NET核心和JQuery不顯眼的AJAX不工作
- 18. 不顯眼的jQuery和Rails的AJAX和表單驗證
- 19. Mootools的Ajax請求
- 20. 有一點我不明白的不顯眼的javascript
- 21. 通過計時器調用不顯眼的javascript
- 22. 如何不顯眼地禁用Javascript和Prototype的提交按鈕?
- 23. 如何使用JQuery使這個舊的JavaScript/ASP Classic代碼(乾淨)不顯眼?
- 24. 如何使用asp.net mvc 3不顯眼的JavaScript驗證與嚮導?
- 25. javascript - 使用mootools從不同的javascript函數調用javascript addEvent函數
- 26. 將不顯眼的JavaScript與Pusher結合起來
- 27. jQuery Mobile的不顯眼模式
- 28. 使用Mootools的
- 29. 使用Mootools的
- 30. 如何讓我的Rails 3表單中的JavaScript不顯眼?
你是什麼意思的「不顯眼」? – Bojangles 2011-12-27 02:49:01
@JamWaffles:他指的是ASP.Net MVC功能。 – SLaks 2011-12-27 02:51:24
「Unobtrusive Javascript」是一種編碼和設計風格,不是您安裝的產品或包含的庫。 MVC3不會讓你使用任何你喜歡的客戶端代碼嗎? – nnnnnn 2011-12-27 02:52:42