打开下载对话框,以及其他 ajax 怪异-6ren"> 打开下载对话框,以及其他 ajax 怪异-我们最近在我们的服务器上建立了一个新网站:Windows 2K8 R2/IIS7/ColdFusion8 Ent。在本地工作没有问题的关键查询现在在生产中无法工作。 使用下面的 cfc 函数中的 使浏-6ren">
gpt4 book ai didi

jquery - 打开下载对话框,以及其他 ajax 怪异

转载 作者:行者123 更新时间:2023-12-01 08:20:54 26 4
gpt4 key购买 nike

我们最近在我们的服务器上建立了一个新网站:Windows 2K8 R2/IIS7/ColdFusion8 Ent。在本地工作没有问题的关键查询现在在生产中无法工作。

使用<cfcontent type="text/json">下面的 cfc 函数中的 使浏览器在模板调用此函数时打开下载对话框。

<cffunction name="getPolls" access="remote" returntype="any" hint="Gets Polls">
<cfargument name="poll_id" type="numeric" required="true">
<cfset var qPoll = 0>
<cfquery name="qPoll" datasource="#application.datasource#">
select * from polls where poll_id = #arguments.poll_id#
</cfquery>
<cfcontent type="text/json">
<cfreturn qPoll>
</cffunction>

下面是调用上述函数的 jQuery 代码。当此代码在模板 (test.cfm) 内运行时,下载对话框将打开,要求我保存文件 test.cfm,而不是实际浏览模板。

$(function(){       
var poll_id = global_poll_id || 0;
var uniqueid = new Date().getTime();
$.getJSON("/cfcs/poll.cfc?method=getPolls&returnformat=json&queryformat=column&uniqueid=" + uniqueid, {"poll_id":poll_id}, function(res,code) {
alert(res.ROWCOUNT); // error here
})
})

如果我删除 <cfcontent type="text/json">从功能上来说,不再出现下载对话框;但是,ajax 回调似乎没有触发并且返回错误:

res is not defined

最佳答案

json 的正确 mime 类型是 application/json,因此添加 text/json 可能会导致下载提示,因为此 mime 可能未在 IIS 中映射。

您并不严格需要添加cfcontent,操作 header 可能是更好的方法。不管怎样,jQuery 都会将其解析为 json。检查网络检查器中的响应和 header ,您可能会找到有关该问题的更多信息。

关于jquery - <cfcontent type ="text/json"> 打开下载对话框,以及其他 ajax 怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7454518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com