开发者

Return value shows error within success method of .ajax()

开发者 https://www.devze.com 2023-02-13 23:28 出处:网络
I have a jQuery ajax call in my coldfusion page which is as below: function getData(paramValue) { var URL = \"/cfc/**somecfc.cfc**?method=**somemethod**\";

I have a jQuery ajax call in my coldfusion page which is as below:

function getData(paramValue)
{
    var URL = "/cfc/**somecfc.cfc**?method=**somemethod**";
    $.ajax({   
    type: "POST",   
    url: URL,   
    data: ({ paramValue: paramValue}),
    dataType: "text",
    success: function(data) { alert(data);},
    error:function (xhr, ajaxOptions, thrownError){                     
            alert("xhr.status = " + xhr.status);                     
            alert("thrownError = " + thrownError);                      }
    });
}   

some method in somecfc returns a text value. When I try to view the data within success, it shows the following error:

"<wddxPacket version='1.0'><header/><data><string>ERROR: . &lt;br /&gt;Element SETTINGS is undefined in a Java object of type class [Ljava.lang.String;.</string></data></wddxPacket>"

Since it shows the error from within success, there seems to be problem with the return data or ?

Any help to fix this would be highly appreciated.

the code in the cfc method is as follows:

<cffunction name="somemethod" access="remote" returntype="any" o>
    <cfargument name="paramValue" type="string" required="yes" >
    <cfset var returnValue = "" />
        <cfquery name="someQry" datasource="#variables.settings['dsn']#"  >
            SELECT  value_name 
            FROM    valuesTbl 
            WHERE   value_Id = <cfqueryparam value="#arguments.paramValue#" cfsqltype="cf_sql_varchar">
        开发者_开发知识库</cfquery>
        <cfset returnValue =  #someQry.value_name# />
    <cfreturn returnValue />
</cffunction>

returnValue variable has only 1 string value. Hope this helps!


You have 1 success and 1 failure going on. The Ajax request went according to plan, you made a request (valid) and obtained a valid response (some text, xml specifically). It appears that there was an exception thrown on the ColdFusion side that it was able to catch and convert to a response (the xml you received from you ajax request).

IE: Your ajax request went well (returned HTTP 200), but something went wrong on the ColdFusion side. You will only reach the error handler if there was an HTTP 500/400 series error.


ColdFusion (by default) actually returns a status code of 200 with application errors, instead of the proper 500.x response. $.ajax looks at the HTTP status code (<> 200) to determine whether to fire the "error" callback.


Thank You all for responding to my question. the error was on coldfusion side. It was related to the DSN I was using by #Application.Settings['DSN']# which was not available remotely as it was out of the scope for this request.

Thanks again!

0

精彩评论

暂无评论...
验证码 换一张
取 消