有没有办法通过ajax调用返回javascript渲染的JSON
我遇到的情况是,我必须运行一些 javascript 并从我的站点获取客户端站点的响应,并且由于跨域脚本安全性,我正在尝试考虑执行此操作的最佳方法。 我可以在客户端页面上放置一段代码。 我可以随意修改我自己的网站。
一种选择是通过 iframe 打开页面,让其网站上的代码片段运行以获取响应,并设置一个 cookie,我可以轮询该 cookie 以获取响应...哎呀...
我一直在考虑不同的方法这样做,我正在努力发挥创意。我是一个后端人员,有一点 javascript 经验,但不需要处理跨域的东西。如果有任何帮助,我将不胜感激。 谢谢,
I have a situation that I have to run some javascript and get a response on a clients site from my site, and I'm trying to think of the best way to do this because of cross domain scripting security.
I have access to placing a snippet of code on a client page.
I can modify my own site as much as I want.
One option is to open the page up via an iframe have the snippet on their site run get the response and set a cookie that I can poll for to get the response from...yikes...
I have been thinking of different ways to do this, and I'm trying to get creative. I'm a backend guy with a bit of javascript experience, but nothing having to deal with cross domain stuff. Please I would appreciate any help.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在您的情况下使用 JSONP 。
JQuery 示例可以在此处找到
You could use JSONP in your situation.
Example with JQuery could be found here
使用您在客户端的代码片段动态创建 iframe - 然后您将位于客户端域沙箱中,并且能够向您的网站发送请求
with your snippet on the client side create the iframe dynamically - then you will be in a clients domain sandbox and will be able to send a request to your site
也许您可以通过 ajax 调用来调用 Web 服务,并通过以下方式返回 JSON 字符串。
然后,在 Web 服务调用成功(即此处的方法 asmxdata() )时,您可以通过以下方式将 JSON 字符串评估为 JSON 对象:
并为控件分配值
如果有任何不清楚的地方请评论。
May be you can call a web service via ajax call and return JSON string by following way..
Then on success of the Web service call (i.e method asmxdata() in here) you can evaluate the JSON string into a JSON object by following way:
and assign values to controls
If anything is unclear please Comment.