在CFC上使用AJAX时出现501错误



我有以下表格:

<!DOCTYPE html>
<head>
</head>
<body>
<div>
    <label>
        <h1>Input 1</h1>
    </label>
    <form>
        <input type="text" name="input_1" class="input">
    </form>
</div>
<!---Javascipt Sources --->
<script src="js/vendor/jquery-1.9.1.min.js"></script>
<script src="js/form.js"></script>
</body>
</html>

使用以下Javascript:

$(document).ready(function(e) {
    $('.input').blur(function() {
        var number = $('.input');
        var data = 'number=' + number.val();
        $.ajax({
            url: "cfc/form.cfc",
            method: "read",
            type: "post",
            data: data,
            success: function(html) {
                if (html == 1) {
                    alert('wyslane');
                }
                else {
                    alert('wrong');
                }
            }
        });
        return false;
    });
});

指向以下CFC:

<cfcomponent>
<cffunction name="Read" access="remote" output="false">
    <cfreturn true>
</cffunction>
</cfcomponent>

我在Chrome的控制台上得到以下错误信息:"READ http://127.0.0.1:8500/Google%20Drive/testing/cfc/form.cfc 501 (Method READ is not is not implemented by this servlet for this URI) "

下面是这个调用的预览页面:

Apache Tomcat/7.0.23 -错误报告

HTTP状态501 -方法ADDTOSESSION is not is not by this servlet for this URI

类型状态报告

消息方法ADDTOSESSION is not is not by this servlet for this URI

描述服务器不支持完成此请求所需的功能(方法ADDTOSESSION is not not由此servlet for this URI实现)。

Apache Tomcat/7.0.23

我使用URL http://127.0.0.1:8500/Google%20Drive/testing/cfc/form.cfc登录RDS后可以正常访问CFC。

是否有一些我做错了代码明智,或者这是一些时髦的内置服务器?我也在Google Drive文件夹外尝试过,直到webroot,但我得到了同样的错误。应授予驱动器本身的所有适用权限(User, Admin, System)。

Windows 7/ColdFusion 10

CFC方法名必须作为HTTP参数传递(通过formurl)。尝试从设置中删除method: "read",并将?method=read附加到url参数,如下所示:

$.ajax({
        url: "cfc/form.cfc?method=read",
        type: "post",
        data: data,
        success: function(html) {
            if (html == 1) {
                alert('wyslane');
            }
            else {
                alert('wrong');
            }
        }
 });

感谢@imthepitts为我指出了正确的道路。我复制粘贴了你的代码,得到了一个500的错误。我稍微修改了一下,让它工作:

    $.ajax({
            url: "cfc/form.cfc",
            type: "post",
            data: {
                method: "read",
                input1: 'hi'},
            success: function(html) {
                if (html == 1) {
                    alert('wyslane');
                }
                else {
                    alert('wrong');
                }
            }
     });

作为一个侧面问题,我在哪里发现我必须通过表单或URL传递它?关于如何处理AJAX调用,我似乎不断得到相互矛盾的信息,并希望有一些来源可以参考。谢谢你的帮助。

最新更新