1

我不知道如何在 RestXQ 中返回 JSONP。添加 let $x := util:declare-option("exist:serialize", fn:concat("method=json jsonp=",request:get-parameter("callback", "callback"))) 到函数后,我收到错误消息:

err:XPTY0004:如果在静态分析阶段发现表达式具有不适合表达式出现的上下文的静态类型,或者在动态求值阶段发现表达式的动态类型不合适,则属于类型错误值与 2.5.4 序列类型匹配中的匹配规则指定的所需类型不匹配。

GET 函数的开头是:

declare
    %rest:GET
    %rest:path("/demo/contacts/submit")
    %rest:query-param("email", "{$email}", '')     
    %rest:query-param("nomail", "{$nomail}", 0)    
    %rest:produces("application/javascript")
    %output:media-type("application/javascript")
    %output:method("json")
function contacts:submit($email as xs:string*, $nomail as xs:integer*)
{


    try
    {

        let $x := util:declare-option("exist:serialize", fn:concat("method=json jsonp=",request:get-parameter("callback", "callback")))
4

2 回答 2

3

正如eXist-open 邮件列表中所讨论的(我建议加入!),请求模块的get-parameter()功能在 RestXQ 函数中不可用。相反,您可以通过注释获取callback参数。%rest:query-param添加%rest:query-param("callback", "{$callback}", '')到您的contacts:submit()功能中,我认为您会更近一步。

于 2015-03-14T01:42:47.943 回答
2

@joewiz 是正确的。您最初的问题与使用来自 RESTXQ 的 eXist 请求模块有关,该模块不受支持。

此外,RESTXQ目前不支持 JSONP 序列化。如果您想使用 JSONP 序列化,目前最好的办法是自己管理 JSON 的序列化,可能使用 xqjson 库或类似库,然后使用 concat 或类似库将结果包装在 JSON 函数中。

于 2015-03-16T18:08:44.273 回答