简体   繁体   English

AJAX调用Web服务

[英]AJAX call to web services

The following article on msdn provides the ASP.NET AJAX solution of calling web service with AJAX... http://msdn.microsoft.com/en-us/magazine/cc163499.aspx like 以下关于msdn的文章提供了使用AJAX调用Web服务的ASP.NET AJAX解决方案... http://msdn.microsoft.com/en-us/magazine/cc163499.aspx like

<asp:ScriptManager ID="_scriptManager" runat="server">
  <Services>
    <asp:ServiceReference Path="StockQuoteService.asmx" />
  </Services>
</asp:ScriptManager>

And then to use the class name directly in Jscript. 然后直接在Jscript中使用类名。 But when I uploaded the service on other domain and tried to do the same, it wouldn't work. 但是,当我将服务上传到其他域并尝试执行相同操作时,它将无法正常工作。 Is there no way I can do it or am I missing something? 有没有办法可以做到,或者我错过了什么? Thanks in advance... 提前致谢...

Due to the same origin policy restriction this is not possible. 由于相同的原产地政策限制,这是不可能的。 You cannot perform cross domain AJAX calls. 您无法执行跨域AJAX调用。 One possible workaround is to use JSONP but you will need to have a web service which supports it. 一种可能的解决方法是使用JSONP,但是您将需要具有支持它的Web服务。

You might like to give this a whirl if you are able to use Jquery: 如果你能够使用Jquery,你可能想要给它一个旋转:

http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

请安装Fiddler2并监控您的请求/响应,这对解决ajax和Web服务问题非常有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM