6 Replies Latest reply: Feb 8, 2012 10:14 AM by Tayyab Hussain RSS

    Ajax Proxy Error

    Tayyab Hussain

      I need help on this error

       

      window:global: Uncaught SyntaxError: parseJSON (http://localhost/CFIDE/scripts/ajax/package/cfajax.js, line 803)

      info:http: CFC invocation response: {"COLUMNS":["ID","PROVINCE"],"DATA":[[1.0,"Punjab"],[2.0,"KhayberPaktoonKha"],[3.0,"Sindh "],[4.0,"Baluchistan"]]} Who We Are | Site Map |Privacy Policy | Contact Us
      Developed by Tayab Hussain

      info:http: HTTP GET /eco/Places.cfc?method=Getprovince&returnFormat=json&argumentCollection=%7B%7D&_cf_nodebu g=true&_cf_nocache=true&_cf_clientid=D6347871AEC0896D1D0965740EA2C089&_cf_rc=0

      info:http: Invoking CFC: /eco/Places.cfc , function: Getprovince , arguments: {}

      info:LogReader: LogReader initialized

      info:global: Logger initialized

       

      This occured when I tried Related select and wanted to bind Provinces with Cities

       

      The Places.cfc code is

      <cfcomponent>

          <cffunction name="Getprovince" access="remote" returnType="any">

              <cfquery name="Lstprovince">

                  SELECT Id, province

                  FROM province

                  ORDER BY id

              </cfquery>

              <cfreturn Lstprovince>

          </cffunction>

            <cffunction name="GetCity" access="remote" returnType="any">

          <cfargument name="Province" type="any" required="true">

          <cfif ARGUMENTS.Province EQ "">

          <cfelse>

              <cfquery name="LstCity">

                  SELECT Id, province_id, desp

                  FROM city

                  WHERE province_id = #ARGUMENTS.province#

                  ORDER BY id

              </cfquery>

          </cfif>

          <cfreturn LstCity>

          </cffunction>

      </cfcomponent>

       

      Gettingstarted contains

       

      <cfajaxproxy cfc="Places">

      <TD>Province:<BR>

           <cfselect name="SelProvince" bind="cfc:Places.Getprovince()"

                display="Province" value="ID" BindOnLoad="true"/>

      </TD>

      <TD>City:<BR>

                <cfselect name="SelCity" bind="cfc:Places.GetCity({SelProvince})"

                                    display="desp" value="Id"/>

      </TD>

       

      Please can any body help

        • 1. Re: Ajax Proxy Error
          BKBK MVP

          I think you are combining 2 idioms here, which are alternatives to each other. Comment out the line <cfajaxproxy cfc="Places">. Use just

           

          <cfform>

          Province:<BR>

          <cfselect name="SelProvince" bind="cfc:Places.Getprovince()"

                    display="Province" value="ID" BindOnLoad="true"/>

          <BR>

          City:<BR>

                    <cfselect name="SelCity" bind="cfc:Places.GetCity({SelProvince})"

                                        display="desp" value="Id"/>

          </cfform>

          • 2. Re: Ajax Proxy Error
            Tayyab Hussain Community Member

            Hello

            I tried it, no difference but I noticed one strange thing I have a sitefooter.cfm it contans

            <A href="index.cfm">Who We Are</A> |

                        <A href="SiteMap.cfm">Site Map</A> |

                        <A href="privacy.cfm">Privacy Policy</A> |

                        <A href="contact.cfm">Contact Us</A>

                        <BR>Developed by Tayab Hussain </DIV>

                                          </TD>

                                </TR>

                      </TABLE>

            </TD>

            </TR>

            </TBODY>

            </TABLE>

             

            This is called in application.cfc

             

            <cffunction name="onRequestEnd" returnType="void" output="true">

            <!--- Display our Site Footer at bottom of every page --->

            <cfinclude template="SiteFooter.cfm">

                      </cffunction>

             

            When I comment out the <cfinclude template="SiteFooter.cfm"> it works and there is no error. What I think, but, cannot work out how to, is the application.cfc adds DOCTYPE html element to every request served by CF. This also includes JSON requests to places.cfc. However HTML code in JSON replies is a syntax error, and replies cannot be parsed. In other words I must ensure that replies from cfselect bind functions are pure JSON without any additions, even whitespaces will brake things. Please do comment

            • 3. Re: Ajax Proxy Error
              BKBK MVP

              There you are then. Application.cfc adds the footer information to the JSON response. The footer information is non-JSON. Since ColdFusion automatically validates JSON responses when parsing them, the result is the error you saw.

               

              JSON:

              {"COLUMNS":["ID","PROVINCE"],"DATA":[[1.0,"Punjab"],[2.0,"KhayberPakt oonKha"],[3.0,"Sindh"],[4.0,"Baluchistan"]]}

               

              Non-JSON(causing error):

              Who We Are | Site Map |Privacy Policy | Contact Us

              Developed by Tayab Hussain

               

              Nevertheless, I would still leave out cfajaxproxy tag.

              • 4. Re: Ajax Proxy Error
                Tayyab Hussain Community Member

                That was quick, so how should I code he footer?

                • 5. Re: Ajax Proxy Error
                  BKBK MVP

                  Perhaps something like this:

                   

                  <cffunction name="onRequestEnd" returnType="void" output="true">

                      <cfargument name="targetPage" type="string" required="true">         

                     <cfif listLast(arguments.targetPage,".") neq "cfc">

                          <cfinclude template="sitefooter.cfm">

                      </cfif>

                  </cffunction>

                  • 6. Re: Ajax Proxy Error
                    Tayyab Hussain Community Member

                    Thanks, it worked