Coldfusion cfc返回json数据错误及问题
我有两台服务器,分别是开发服务器和生产服务器,都运行 IIS7 和 Coldfusion 8 Standard。
然而,在生产环境中,整个网站都采用 ssl,除了登录之外的所有页面都是 ssl。
我正在研究半冷融合/半ajax驱动的站点搜索。
一切在我们的开发服务器上运行顺利,当转移到生产环境时,我开始遇到非常奇怪的错误。
就像数据没有以 json 格式返回数据的事实一样,即使 returntype=json,并且我在返回数据的数组周围有序列化json。
然后,当我尝试删除 returntype=json 时,它总是会说无效令牌。
当ajax被调用时,它确保指定json的数据类型,并在url中返回格式说是json。所有这些在我们的开发服务器上都运行良好,但 ajax 部分拒绝在生产环境中运行。
一开始我以为是ssl的问题,如果ajax url是ssl的话,就会报错说access-origin同源策略,所以我把ajax url改成非ssl,然后就这样了要么数据不是返回的 json,要么显示无效令牌。
在我的 cfc 中,我有一个主 cfc,它获取我需要的所有数据,以我需要的各种方式对其进行格式化,然后将这些结果放入数组内的不同位置。
然后运行然后
我尝试去掉 cffunction 命令上的 returntype=json ,当我尝试直接查看 url 中的 cfc 时,这似乎有效。但是当ajax调用它时,要么它说无效令牌。
当我在开发上运行相同的代码时,没有错误,所有 ajax 都 100% 工作。
对于问题可能是什么有什么建议吗?
谢谢
I have two servers, development and production, both running IIS7 and Coldfusion 8 Standard.
However on production the whole website is on ssl, all pages except for the login are ssl.
I was working on a half coldfusion/half ajax powered site search.
Everything ran smoothly on our dev server, when moved to production, I started to get really odd errors.
Like the fact that the data wasn't returnning data in json format, even though returntype=json, and i had serializejson around the array that was returnning the data.
Then when I tried removing the returntype=json, it would always say invalid token.
When the ajax is called, it makes sure to specify the datatype of json, and returnformat in the url say's json. And all of this works fine on our dev server, but the ajax part refuses to work on production.
At first I thought it was because there was the ssl issue, which if the ajax url is ssl, then it error's out saying access-origin same-origin policy, so then I change the ajax url to non-ssl, and then it does the either the data is not json being returned back or it says invalid token.
In my cfc, I have a main cfc that get's all the data i need, format's it in the various way's I need, then put's those results into different position's inside an array.
Then run's then
I have tried taking away the returntype=json on the cffunction command, and that seems to work when I try to view the cfc in the url directly. But when ajax calls it, either it says invalid token.
When I run the same code on dev, no errors, all ajax works 100%.
Any suggestions for what the issue can be?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,在我从 ajax 请求中删除 dataType: 'json' 后,它开始工作!
亲爱的妈妈。我想知道为什么生产与开发之间如此奇怪。
谢谢。
Well apparently, after I removed the dataType: 'json' from the ajax request it started to work!
sweet mama. I wonder why it's so weird on production vs dev.
Thanks.
我想我知道这个问题,几年前我就遇到过这个问题。您必须在 JSON 之前发送正确的标头。在开始输出任何内容之前尝试其中之一:
这样,jQuery 将能够正确地将其识别为从服务器返回的 JSON。如果你告诉 jQuery 期望 json,并且服务器不发送此标头,有时它会有点困惑:/
希望这有帮助!
I think I know the issue, I ran into this a few years ago. You have to send the correct header back before your JSON. Try one of these before you start outputting anything:
This way, jQuery will be able to properly identify it as JSON coming back from the server. If you tell jQuery to expect json, and the server doesn't send this header, sometimes it gets a little confused :/
Hope this helps!