32 Replies Latest reply on Oct 30, 2013 1:54 AM by tribule

    CFC 403 Forbidden Error

    pjunkie

      I am trying to invoke a CFC via a URL:

       

      $(function () {

          'use strict';

       

          // Load countries then initialize plugin:

          $.ajax({

                 url: 'https://....countries.cfc?method=getCountries',

             // url: '/autocomplete/content/countries.txt',

              dataType: 'json'

          }).done(function (source) {

       

              var countriesArray = $.map(source, function (value, key) { return { value: value, data: key }; }),

                  countries = $.map(source, function (value) { return value; });

       

       

      And get the following error:

       

       

      NetworkError: 403 Forbidden -

       

      Any help in fixing this would be appreciated.

        • 1. Re: CFC 403 Forbidden Error
          duncancumming Level 3

          What happens if you try and access that URL directly in your browser, rather than trying to load it in via AJAX?

          • 2. Re: CFC 403 Forbidden Error
            pjunkie Level 1

            I get the same error

             

            403

            Forbidden
            • 3. Re: CFC 403 Forbidden Error
              tribule Level 2

              403 is not a ColdFusion error as such, it is a web server error. Therefore, the resource in question has an access issue e.g. IP block, permission issue, or other security-related issue that is stopping access. The error is also given sometimes when a resource URL cannot be opened. You need to look at that CFC and see where it goes wrong. Debug it line by line and put break points in to see where it gets to before the error is given. Check file paths, any rewrites, and server security settings for the resource. Can you call some code in the CFC before it errors? You have to be Sherlock Holmes sometimes

              1 person found this helpful
              • 4. Re: CFC 403 Forbidden Error
                pjunkie Level 1

                The server admin opened remote access but now I am getting this error:

                 

                 

                Error Summary

                HTTP Error 404.5 - Not Found

                The request filtering module is configured to deny the URL sequence.

                 

                 

                When I googled this error I found this:

                 

                http://www.iis.net/configreference/system.webserver/security/requestfiltering/denyurlseque nces

                 

                 

                How can this issue be resolved?

                • 5. Re: CFC 403 Forbidden Error
                  pjunkie Level 1

                  Is there a simple ajax cold fusion example that does not require remote access?

                  • 6. Re: CFC 403 Forbidden Error
                    pjunkie Level 1

                    The CFC works now when i access it via the url.

                     

                    Now I need to know how can I change this:

                     

                    $(function () {

                        'use strict';

                     

                        // Load countries then initialize plugin:

                        $.ajax({

                     

                        url: 'autocomplete/content/countries.txt',

                            dataType: 'json'

                        }).done(function (source) {

                     

                    To this:

                     

                    $(function () {

                        'use strict';

                     

                        // Load countries then initialize plugin:

                        $.ajax({

                                url: 'countries.cfc?method=getCountries',

                            dataType: 'json'

                        }).done(function (source) {

                     

                     

                     

                    I tried just added the URL and it doesn't work

                    • 7. Re: CFC 403 Forbidden Error
                      tribule Level 2

                      Please install HTTP trace or use developer tools in the browser to see the HTTP requests. Enable HTTP tracing and then load the page. Are there any errors e.g. 401's or 404's etc. Make sure all URLs in the script are fully qualified (include http, domain and path etc) just to rule out that a file cannot be located.The error with the request filtering module suggests that a URL is either being blocked or is malformed. Post the result of your HTTP trace.

                       

                      Also, make sure your ajax request is on the same domain - is it?

                       

                      Also you are calling the ajax script securely - did you try using http:// instead of https:// - is your main page served securely? Some background information would be useful. Please post the code again with made up domain names, if you like.

                      • 8. Re: CFC 403 Forbidden Error
                        pjunkie Level 1

                        I intalled HTTP Trace it gives me no errors

                         

                        Firebug doesn't either.

                         

                        I am using a full https path. Yes the page is served securely.

                         

                        Here is the code: (Domain removed because its our DEV server)

                         

                         

                        /*jslint  browser: true, white: true, plusplus: true */

                        /*global $: true */

                         

                        $(function () {

                            'use strict';

                         

                            // Load countries then initialize plugin:

                            $.ajax({

                                    url: 'https://...../countries.cfc?method=getCountries',

                                dataType: 'json'

                            }).done(function (source) {

                         

                                var countriesArray = $.map(source, function (value, key) { return { value: value, data: key }; }),

                                    countries = $.map(source, function (value) { return value; });

                         

                                // Setup jQuery ajax mock:

                                $.mockjax({

                                    url: '*',

                                    responseTime: 2000,

                                    response: function (settings) {

                                        var query = settings.data.query,

                                            queryLowerCase = query.toLowerCase(),

                                            re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi'),

                                            suggestions = $.grep(countriesArray, function (country) {

                                                 // return country.value.toLowerCase().indexOf(queryLowerCase) === 0;

                                                return re.test(country.value);

                                            }),

                                            response = {

                                                query: query,

                                                suggestions: suggestions

                                            };

                         

                                        this.responseText = JSON.stringify(response);

                                    }

                                });

                         

                                // Initialize ajax autocomplete:

                                $('#autocomplete-ajax').autocomplete({

                                    // serviceUrl: '/autosuggest/service/url',

                                    lookup: countriesArray,

                                    lookupFilter: function(suggestion, originalQuery, queryLowerCase) {

                                        var re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi');

                                        return re.test(suggestion.value);

                                    },

                                    onSelect: function(suggestion) {

                                        $('#selction-ajax').html('Selected Country: ' + suggestion.value + ', ' + suggestion.data);

                                    },

                                    onHint: function (hint) {

                                        $('#autocomplete-ajax-x').val(hint);

                                    },

                                    onInvalidateSelection: function() {

                                        $('#selction-ajax').html('Selected Country: none');

                                    }

                                });

                         

                                // Initialize autocomplete with local lookup:

                                $('#autocomplete').autocomplete({

                                    lookup: countriesArray,

                                    onSelect: function (suggestion) {

                                        $('#selection').html('Selected Country: ' + suggestion.value + ', ' + suggestion.data);

                                    }

                                });

                               

                                // Initialize autocomplete with custom appendTo:

                                $('#autocomplete-custom-append').autocomplete({

                                    lookup: countriesArray,

                                    appendTo: '#suggestions-container'

                                });

                         

                                // Initialize autocomplete with custom appendTo:

                                $('#autocomplete-dynamic').autocomplete({

                                    lookup: countriesArray

                                });

                               

                            });

                         

                        });

                        • 9. Re: CFC 403 Forbidden Error
                          tribule Level 2

                          Are the domains of the calling page and the Ajax call the same?

                           

                          Did you get rid of the "The request filtering module is configured to deny the URL sequence." error, and where and when was that error being shown btw?

                           

                          Can you also retry with 'use strict'; commented out?

                          • 10. Re: CFC 403 Forbidden Error
                            pjunkie Level 1

                            I am not sure of what you mean by this:

                             

                            Are the domains of the calling page and the Ajax call the same?

                             

                            The calling page is like this: https://www.citiprogram.org/index.cfm?pageID=86

                             

                            The AJAX is in a sub directory of the root. Do they all need to be at the same level?

                            • 11. Re: CFC 403 Forbidden Error
                              pjunkie Level 1

                              Commenting out "use strict" didn't work

                              • 12. Re: CFC 403 Forbidden Error
                                pjunkie Level 1

                                Yes I got rid of the error. I forgot what was making it happen.

                                • 13. Re: CFC 403 Forbidden Error
                                  tribule Level 2

                                  What I mean is, if the page is served from https://www.citiprogram.org then the Ajax call needs to be targetting the same domain e.g.

                                   

                                  $.ajax({ 

                                  url: 'https://www.citiprogram.org/whatever/countries.cfc?method=getCountries',

                                  ...

                                  })...

                                   

                                  They don't need to be at the same level; I was just trying to work out where your Ajax request was being made to, and you say it is the same domain, so that is another issue ruled out.

                                   

                                  So what error do you see now, and at what stage does it occur. Does it occur when the Ajax call is invoked, in which case what HTTP status code do you see for the Ajax request? 200 or 302 etc? Hard to pinpoint an error without seeing the code working.

                                  • 14. Re: CFC 403 Forbidden Error
                                    pjunkie Level 1

                                    Yes they are on the same one.

                                     

                                    I don't see an error. It just doesn't work.

                                     

                                    It works when I point to a txt doc but not to a CFC.

                                    • 15. Re: CFC 403 Forbidden Error
                                      tribule Level 2

                                      is '#selction-ajax' the correct spelling for this DIV? Need to see all the code - can you zip and put it online?

                                      • 16. Re: CFC 403 Forbidden Error
                                        pjunkie Level 1

                                        The code that I am using is here https://github.com/devbridge/jQuery-Autocomplete

                                        • 17. Re: CFC 403 Forbidden Error
                                          pjunkie Level 1

                                          yes selection is misspelled orignally in the code.

                                           

                                          I think I MIGHT know what the problem is.

                                           

                                          the countries.txt doc has the data in a certain format:

                                           

                                          "AD": "Andorra",

                                              "AE": "United Arab Emirates",

                                              "AF": "Afghanistan",

                                              "AG": "Antigua and Barbuda",

                                           

                                           

                                          The AJAX code seems to be looking for the data in that format:

                                           

                                             var countriesArray = $.map(source, function (value, key) { return { value: value, data: key }; }),

                                                      countries = $.map(source, function (value) { return value; });

                                           

                                           

                                          So I need to somehow put my query results in this format.

                                           

                                          Thoughts?

                                          • 18. Re: CFC 403 Forbidden Error
                                            tribule Level 2

                                            According to the jQuery docs for that autocomplete code, the countries need to look like this (JavaScript array):

                                             

                                            var countries = [

                                               { value: 'Andorra', data: 'AD' },

                                               ...

                                               { value: 'Zimbabwe', data: 'ZZ' }

                                            ];

                                             

                                            perhaps that is what the format needs to be, so that $.map can get the items that it needs? It seems your issue may actually be JavaScript related. Your query to get the countries needs to output them as a JS array perhaps?

                                            • 19. Re: CFC 403 Forbidden Error
                                              pjunkie Level 1

                                              Yes I think the data format is the issue.

                                               

                                              Can you give me any suggestions on formatting my query results correctly?

                                              • 20. Re: CFC 403 Forbidden Error
                                                tribule Level 2

                                                I downloaded the github jQuery-autocomplete, placed it in a folder and loaded index.htm and it worked straight out of the box for me, so I'm not sure why you are using the CFC at all. It has a countries.txt file with all the country data. Why can't you use this code?

                                                • 21. Re: CFC 403 Forbidden Error
                                                  pjunkie Level 1

                                                  It works for me too when I use the countries.txt file but I need to use it with data from the database something other than countries

                                                  • 22. Re: CFC 403 Forbidden Error
                                                    tribule Level 2

                                                    Ah, you make no mention of using this script for something other than countries The 'https://....countries.cfc?method=getCountries script needs to produce the same formatted output as countries.txt i.e. like this, and it needs to contain the same two array entries I'd guess:

                                                     

                                                    {

                                                        "AD": "Andorra",

                                                       ...

                                                        "??": "Last entry"

                                                    }

                                                     

                                                    Can you ensure that countries.cfc returns this format.

                                                     

                                                    What information do you need to display other than country data? Please be more detailed.

                                                    • 23. Re: CFC 403 Forbidden Error
                                                      pjunkie Level 1

                                                      I do need to display th countries but I also need to do this again for a different data set.

                                                       

                                                      That is why I was trying to get the cfc for the countries to work first so I can repeat it on the other data.

                                                       

                                                      The other data is a list of organizations that needs to be pulled from the database. The data changes so a txt doc wouldn't work

                                                      • 24. Re: CFC 403 Forbidden Error
                                                        tribule Level 2

                                                        I understand the need for dynamic data but you've gone well outside the remit of a ColdFusion issue here...

                                                         

                                                        Your countries.cfc?method=getCountries needs to output something. Does it output its data in the same format as in countries.txt? Please do that first; that is very easy to do. Ensure the data that comes out in the page looks like a JavaScript object, like in countries.txt. You need to post some code for countries.cfc

                                                        • 25. Re: CFC 403 Forbidden Error
                                                          pjunkie Level 1

                                                          No it doesn't. I will need help with the formatting.

                                                           

                                                          Here is the code for the cfc.

                                                           

                                                          <cffunction access="remote" name="getCountries" output="yes" returntype="array">

                                                          <cfargument name="search" type="any" required="false" default="">

                                                           

                                                          <!--- Define variables --->

                                                          <cfset var data="">

                                                          <cfset var result=ArrayNew(1)>

                                                           

                                                          <!--- Do search --->

                                                          <cfquery datasource="#request.dsn#" name="data">

                                                          SELECT     intCountryId, strCountry

                                                          FROM tblCountries

                                                          ORDER BY strCountry

                                                          </cfquery>

                                                           

                                                          <!--- Build result array --->

                                                          <cfloop query="data">

                                                          <cfset ArrayAppend(result, strCountry)>

                                                          </cfloop>

                                                           

                                                          <!--- And return it --->

                                                          <cfreturn result>

                                                              </cffunction>

                                                          • 26. Re: CFC 403 Forbidden Error
                                                            tribule Level 2

                                                            Please send the schema for tblCountries, and give one example record.

                                                            • 27. Re: CFC 403 Forbidden Error
                                                              pjunkie Level 1

                                                              I think this is what you need (see attached image). Let me know if you were looking for something else.

                                                               

                                                              countries.png

                                                              i actually need the intCountryID to be returned.

                                                              • 28. Re: CFC 403 Forbidden Error
                                                                tribule Level 2

                                                                Off the top of my head, I'd use this simple code to test with - this replaces your code above:

                                                                 

                                                                <cfquery datasource="#request.dsn#" name="data">

                                                                SELECT intCountryId, strCountry

                                                                FROM tblCountries

                                                                ORDER BY strCountry

                                                                </cfquery>

                                                                 

                                                                {

                                                                <cfoutput query="data">

                                                                    "#intCountryId#": "#strCountry#"#IIF(currentrow lt recordcount, DE(","), DE(""))#

                                                                </cfoutput>

                                                                }

                                                                 

                                                                 

                                                                This will output all the records in the format:

                                                                 

                                                                {

                                                                "1": "Andorra",

                                                                "2": "United Arab Emirates",

                                                                ...

                                                                "ZW": "Zimbabwe"

                                                                }

                                                                 

                                                                No idea if it will work, this is a bespoke coding mash-up requirement.

                                                                • 29. Re: CFC 403 Forbidden Error
                                                                  pjunkie Level 1

                                                                  I am just going to use the regular CF AJAX code.

                                                                   

                                                                  cfinput type="text"

                                                                          name="institution"

                                                                          autosuggest="cfc:ajaxlookup.getInstitutions({cfautosuggestvalue})" size="45">

                                                                   

                                                                   

                                                                  How can I do the lookup with the name but populate the field with another value? In this case, the user will see the institution name, but I want to institution ID populated in the form.

                                                                  • 30. Re: CFC 403 Forbidden Error
                                                                    tribule Level 2

                                                                    I am not familiar with cfinput. Also you did not say why the code above could not be used. Did you try it?

                                                                    • 31. Re: CFC 403 Forbidden Error
                                                                      pjunkie Level 1

                                                                      I didn't quite understand the sytax or where to put it. I am going to try it now.

                                                                      • 32. Re: CFC 403 Forbidden Error
                                                                        tribule Level 2

                                                                        Create a template, test.cfm, with only the code I gave you above. In your Ajax call refer to test.cfm in order to test it.