如何通过asp.net中的javascript从另一个网站获取文本内容? [英] How to get text content from another website by javascript in asp.net?

查看:66
本文介绍了如何通过asp.net中的javascript从另一个网站获取文本内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...

我正在asp.net中创建一个Web应用程序,我想在其中向用户提供一个JavaScript代码,通过该代码用户可以将内容从我的网站获取到他/她自己的网站.

我使用了一个通用处理程序来处理我网站中的用户请求.
所以,现在我该怎么做,我已经尝试使用jQuery ..
jQuery只能处理来自当前服务器的请求,不能处理来自其他服务器的请求(如果我没记错的话)

www.otherwebsite.com上的代码

Hello...

I''m creating a web application in asp.net in which I would like to give user a one JavaScript code, through which the user can get content from my website to his/her own website.

I''ve used one generic handler to process user request in my website.
so, now How can I do this, i''ve tried using jQuery..
jQuery can only process requests from current server, not from other server (if i''m not wrong)

Code on www.otherwebsite.com

<script type="text/javascript" src="jquery.x.x.js">
 </script>
<script type="text/javascript">
 $(''#result'').load(''www.myWebSite.com/getData.ashx'');
 </script>
<body>
 <div id="result">

 </div>

 </body>



上面的代码不起作用.. :(

还有其他方法可以将内容从我的网站发送到其他网站吗?
任何帮助将不胜感激.

-thanx



Above code isn''t working.. :(

Is there any other way to send content from my website to other website??
any help would be greatly appreciated.

-thanx

推荐答案

(``#result'').load(''www.myWebSite.com/getData.ashx''); </script> <身体> < div id ="result"> </div> </body>
(''#result'').load(''www.myWebSite.com/getData.ashx''); </script> <body> <div id="result"> </div> </body>



上面的代码不起作用.. :(

还有其他方法可以将内容从我的网站发送到其他网站吗?
任何帮助将不胜感激.

-thanx



Above code isn''t working.. :(

Is there any other way to send content from my website to other website??
any help would be greatly appreciated.

-thanx


听起来您想发出跨域AJAX请求,因此应该使用JSONP.您的getData.ashx页面应更改为响应JSONP请求.阅读本文以获取更多信息:从JSON转换为JSONP:绕过相同来源策略 [
It sounds like you want to make a cross-domain AJAX request, so you should use JSONP. Your getData.ashx page should be changed to respond to a JSONP request. Read this article for more information: JSON to JSONP: Bypass Same-Origin Policy[^]


这篇关于如何通过asp.net中的javascript从另一个网站获取文本内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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