使用 ColdFusion CFC 时 JQuery 出现无效 JSON 错误,即使返回看似正确的 JSON
我正在查看 Ben 的示例@ http://www.bennadel.com/blog/1515-Ask-Ben-Building-An-AJAX-jQuery-And-ColdFusion-Powered-Application.htm 并致力于一个极其简单的示例我自己的。但似乎即使 CFC 返回格式正确的 JSON,它总是会在我的错误处理程序中出现以下错误:
Invalid JSON: {"ERRORS":"","SUCCESS":true,"DATA":"id DEX015-002-00, whs W1, qty 9"}
这是 ajax 调用
$.ajax({
type: 'GET',
url: 'bridge.cfc',
data: {
method: 'UpdateQty',
id: 'DEX015-002-00',
whs: 'W1',
qty: '9'
},
dataType:'json',
success: function(res, status, req){ alert("Message from server:\n" + "res: " + res); },
error: function(req, status, err){ "Error from server:\n" + "err: " + err); }
});
这是 CFC“bridge.cfc”
<cfcomponent>
<cffunction name="UpdateQty" access="remote" returntype="struct" returnformat="json" output="false">
<cfargument name="id" required="yes" type="string">
<cfargument name="whs" required="yes" type="string">
<cfargument name="qty" required="yes" type="string">
<cfset res = structNew()>
<cfset res.success = true>
<cfset res.data = "id " & arguments.id & ", whs " & arguments.whs & ", qty " & arguments.qty >
<cfset res.errors = "">
<cfreturn res >
</cffunction>
</cfcomponent>
我缺少什么?
I was looking at Ben's example @ http://www.bennadel.com/blog/1515-Ask-Ben-Building-An-AJAX-jQuery-And-ColdFusion-Powered-Application.htm and wokring on an ultra simplistic example of my own. but it seems like even though the CFC returns properly formatted JSON, it always ends up in my error handler with the error :
Invalid JSON: {"ERRORS":"","SUCCESS":true,"DATA":"id DEX015-002-00, whs W1, qty 9"}
Here's the ajax call
$.ajax({
type: 'GET',
url: 'bridge.cfc',
data: {
method: 'UpdateQty',
id: 'DEX015-002-00',
whs: 'W1',
qty: '9'
},
dataType:'json',
success: function(res, status, req){ alert("Message from server:\n" + "res: " + res); },
error: function(req, status, err){ "Error from server:\n" + "err: " + err); }
});
And heres the CFC "bridge.cfc"
<cfcomponent>
<cffunction name="UpdateQty" access="remote" returntype="struct" returnformat="json" output="false">
<cfargument name="id" required="yes" type="string">
<cfargument name="whs" required="yes" type="string">
<cfargument name="qty" required="yes" type="string">
<cfset res = structNew()>
<cfset res.success = true>
<cfset res.data = "id " & arguments.id & ", whs " & arguments.whs & ", qty " & arguments.qty >
<cfset res.errors = "">
<cfreturn res >
</cffunction>
</cfcomponent>
What am I missing ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常当我遇到这个问题时,这是因为我将调试设置为输出,并且它被附加到我的远程方法的输出上。
尝试将: 添加
到您的
UpdateQty
方法中。Usually when I run into this issue, it's because I have debugging set to output, and it gets tacked on to my remote method's output.
Try adding:
to your
UpdateQty
method.尝试将 output=false 添加到您的 cfcomponent 中。
Try adding output=false to your cfcomponent.