如何在 CFWheels, for Ajax 中启动控制器/操作
How to initiate controller/action in CFWheels, for Ajax?
我已经尝试让cfwheels与FineUploader一起工作了两天,但我只是不知道如何强制jQuery脚本执行控制器/操作。这就是我到目前为止所走的路:
$(document).ready(function() {
var restricteduploader = new qq.FineUploader({
// Since we're using jQuery, use the jQuery way to select the HTML element
element: $('##restricted-fine-uploader')[0],
request: {
type: "POST",
url: $(this).attr("href") + "/index.cfm?controller=users&action=UploadFileXhr&format=json", // References "/say/hello?format=json"
dataType: "json",
endpoint: '/index.cfm?controller=users&action=UploadFileXhr&format=json'
},
multiple: false,
validation: {
allowedExtensions: ['jpeg', 'jpg', 'txt'],
sizeLimit: 5120000000 // 50 kB = 50 * 1024 bytes
},
text: {
uploadButton: 'Click or Drop'
},
showMessage: function(message) {
// Using Twitter Bootstrap's classes and jQuery selector and method
$('##restricted-fine-uploader').append('<div class="alert alert-error">' + message + '</div>');
},
debug: true
});
});
CFWheels文档说我必须使用它来获取异步请求:
(function($){$(document).ready(function(){
// Listen to the "click" event of the "alert-button" link and make an AJAX request
$("#alert-button").click(function() {
$.ajax({
type: "POST",
url: $(this).attr("href") + "?format=json", // References "/say/hello?format=json"
dataType: "json",
success: function(response) {
$("h1").html(response.message);
$("p").html(response.time);
}
});
return false; // keeps the normal request from firing
});
});})(jQuery);
这三行是我试图合并到我的代码中的内容(因为这就是我认为我需要的):
类型:"开机自检",
url: $(this).attr("href") + "?format=json",//References "/say/hello?format=json"
数据类型:"json",
但是我尝试的一切都没有奏效。我什至无法处理我的实际上传代码来使其工作,因为我甚至无法让上传者启动所需的控制器/操作。
希望有人能够为我指出正确的方向。谢谢!
问题也发布到cfWheels邮件列表:https://groups.google.com/forum/?fromgroups=#!topic/cfwheels/UKk_57y9ncQ
我不
熟悉FineUploader,但通常当我在Wheels中执行AJAX请求时,我会使用urlFor()函数来构建正确的控制器/操作位置。
CFWheels - urlFor
我想我知道你面临什么问题。请按照以下步骤操作:
-
确保在控制器中
Say.cfc
为 Ajax 调用提供 JSON 格式:在Say.cfc
的init()
函数中,请确保添加以下内容:<cffunction name="init" hint="It secures component from invalid access"> <!--- this is necessary ---> <cfset provides("json") /> </cffunction>
-
现在,在
hello
操作中,呈现要提供的数据而不进行布局。删除操作中存在的任何<cfabort>
标记:<!--- this will go at the very end of the action ---> <!--- here the attribute data is the data you want to serve: a query, struct or any other custom data generated inside a `<cfsavecontent>` ---> <cfset renderWith(data=data,layout=false) />
我希望这对你有用。
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- 为什么我的控制器没有启动函数.js脚本
- angularjs控制器未启动
- Angular JS$location.path(..)未启动路由控制器
- AngularJS:如何重新启动控制器以更新要监视的数据源模型
- 使用 JavaScript 从控制器启动 Excel 文件
- “控制器”的AngularJS代码无法启动
- 控制器中的$watch在将项推入指令中的数组时未启动
- Ionic:应用程序启动时角度控制器未运行
- 如何从1个控制器启动倒计时计时器并显示在其他angularjs中
- 如何在Ember JS控制器加载时启动一个函数?
- Ionic谷歌地图控制器没有重新启动
- 如果子控制器处于相同状态,则angular ui路由器-嵌套控制器-父控制器将启动两次
- Sencha Touch 2控制器初始化/启动不'不要开火
- 如何在 CFWheels, for Ajax 中启动控制器/操作
- 在控制器将数据发送到jsp之后,如何启动脚本