我已经运行与使用jQuery(和ColdFusion服务器端)Ajax响应的问题。有时工作,有时没有。当我测试了服务器端组件直接调用它 - 它始终工作,所以我想这个问题是与Ajax响应。我得到的SERVERURL,直接从服务器 - 因此它不应该是一个跨域的问题。我只是显示和隐藏DIV-标记,以便它不应该是不确定的URL,然后Ajax响应已被处理。我拉出很多头发了这一点。
I have run into a problem with the AJAX response using jquery (and coldfusion serverside). Sometimes it works and sometimes it doesn't. When I test the serverside component calling it directly - it always works, so I guess the problem is with the ajax response. I get the serverurl, directly from the server - so it shouldn't be a cross-domain issue. I just show and hide div-tags so it shouldn't be about relocating the url before the ajax response has been processed. I am pulling out a lot of hair over this.
在code为addTask方式:
The code for the addTask method:
function addTask(){
var priority = $('#ff-add-task-priority').length > 0? $('#ff-add-task-priority').val() : 0;
$.ajax({
url: settings.server+'/c/Tasks.cfc?method=addTask',
data: { userid: settings.userid,
taskname: $('#ff-add-task-name').val(),
tasknote: $('#ff-add-task-note').val(),
completed: $('#ff-add-task-completed').val(),
priority: priority,
},
type: 'POST',
dataType: 'json',
success: function(response) {
var output = addRow(response, $('#ff-add-task-name').val(), 0,0);
$('#data-list-tasks').append(output);
$('#main').children().addClass('hide');
$('#section-list-tasks').removeClass('hide');
resetForm($('#add-task-form'));
//route('#section-list-tasks');
},
error: function(ErrorMsg) {
console.log('Error', ErrorMsg);
}
});
}
Firebug的输出显示了AJAX调用,有时作品,有时失败:
Firebug output shows that the AJAX calls works sometimes and sometimes it fails.:
POST http://dev.wedoolist.com/c/Tasks.cfc?method=addTask jquery.min.js (linje 2) Error Object { readyState=0, status=0, statusText="error"} #secti...t-tasks (linje 124)
POST http://dev.wedoolist.com/c/Tasks.cfc?method=getTasks 200 OK 152ms jquery.min.js (linje 2)
POST http://dev.wedoolist.com/c/Tasks.cfc?method=addTask 200 OK 146ms jquery.min.js (linje 2)
POST http://dev.wedoolist.com/c/Tasks.cfc?method=addTask 200 OK 133ms jquery.min.js (linje 2)
POST http://dev.wedoolist.com/c/Tasks.cfc?method=addTask 200 OK 133ms jquery.min.js (linje 2)
POST http://dev.wedoolist.com/c/Tasks.cfc?method=addTask 200 OK 131ms jquery.min.js (linje 2)
POST http://dev.wedoolist.com/c/Tasks.cfc?method=addTask jquery.min.js (linje 2) Error Object { readyState=0, status=0, statusText="error"}
更新:
Request-headere
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language da,en-us;q=0.7,en;q=0.3
Content-Length 59
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie CFID=198de696-2168-4911-8639-79ea944c9975; CFTOKEN=0; JSESSIONID=B520084E7DDFB504BC87E200449C3DA7
Host dev.wedoolist.com
Referer http://dev.wedoolist.com/index.cfm?add-task-completed-switch=0&ff-add-task-priority=0
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0
X-Requested-With XMLHttpRequest
更新:
使用招我得到这个错误:
Using fiddler I get this error:
HTTP Error 411. The request must be chunked or have a content length.
任何帮助是非常AP preciated。
Any help is much appreciated.
谢谢
彼得·
推荐答案
我认为你需要的数据参数报价是这样的:
I think you need quotes in the data parameter like this:
data: { 'userid': settings.userid,
'taskname': $('#ff-add-task-name').val(),
'tasknote': $('#ff-add-task-note').val(),
'completed': $('#ff-add-task-completed').val(),
'priority': priority,
},
看看是否有帮助。
See if that helps.
相关推荐
最新文章