是否有用于jsonp的现有工具,例如在jquery中获取xml? [英] Is there an existing tool for jsonp like fetching of xml in jquery?

查看:79
本文介绍了是否有用于jsonp的现有工具,例如在jquery中获取xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在开发的Web服务,我希望我的嵌入式代码(在客户端站点上)从驻留在我的域中的服务器脚本中获取xml文件.

For a web service I'm developing I would like my embedded code (on the client's site) to fetch an xml file from my sever script which resides on my domain.

由于这是一个跨域请求,因此我认为使用jsonp似乎是此类api的事实上的标准.但是,对于我的应用程序来说,使用xml而不是json会更容易.现在,我当然可以将我的xml转换为服务器上的json,然后再次转换为客户端站点javascript中的xml,但这似乎不必要地麻烦.我真正需要的是xmlp解决方案,带有填充的xml.

As this is a cross-domain request I figured to use jsonp as it seems the de facto standard for such apis. However, for my application it would be easier for me to use xml instead of json. Now, I could of course convert my xml to json on the server and then back again to xml in the client's site javascript, but that seems unnecessarily cumbersome. What I really need is and xmlp solution, xml with padding.

我厌倦了谷歌搜索,但找不到能做到这一点的jquery插件.有谁知道一个简单的解决方案?

I tired googling but couldn't find a jquery plug-in that does that. Anyone knows a simple solution?

推荐答案

json起作用的唯一原因是因为页面上包含的javascript可以在窗口中运行而没有任何x域问题.因此,必须保留javascript.但是,您可以缩小xml,确保已正确转义该xml,并将其作为值发送到json对象中.

The only reason json works is because included javascript on your page can run in the window without any x-domain issues. So it must remain javascript. However, you could just minify the xml, make sure it's properly escaped and send it as a value in a json object.

echo 'callback({data: "' + xml string + '"});';

或者类似的东西.

这篇关于是否有用于jsonp的现有工具,例如在jquery中获取xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆