Chester
Chester

Reputation: 1083

501 error when using AJAX on CFC

I have the following form:

<!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>

With the following 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;
    });
});

Which points to the following CFC:

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

I am getting the following error message on the console of 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) "

Below is the preview page for that call:

Apache Tomcat/7.0.23 - Error report

HTTP Status 501 - Method ADDTOSESSION is not is not implemented by this servlet for this URI

type Status report

message Method ADDTOSESSION is not is not implemented by this servlet for this URI

description The server does not support the functionality needed to fulfill this request (Method ADDTOSESSION is not is not implemented by this servlet for this URI).

Apache Tomcat/7.0.23

I can hit the CFC fine after I log in to RDS by using the URL http://127.0.0.1:8500/Google%20Drive/testing/cfc/form.cfc.

Is there something I did wrong code wise, or is this something funky with the built-in server? I have also tried it outside of the Google Drive folder, up to the webroot, but I get the same error. All applicable permissions on the drive itself should be granted (User, Admin, System).

Windows 7 / ColdFusion 10

Upvotes: 0

Views: 1878

Answers (2)

Chester
Chester

Reputation: 1083

Thanks @imthepitts for pointing me down the correct path. I copied and pasted your code and got a 500 error. I modified it a bit to get it to work:

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

As a side questions, where would I find out that I have to pass it via the FORM or URL? I seem to keep getting conflicting information as to what to do with AJAX calls and would like some source to reference. Thank you for you help.

Upvotes: 1

imthepitts
imthepitts

Reputation: 1647

The CFC method name must be passed as an HTTP parameter (via the form or the url). Try removing method: "read" from your settings and append ?method=read to your url parameter like this:

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

Upvotes: 1

Related Questions