【发布时间】:2011-04-01 03:19:55
【问题描述】:
场景:我将使用 AJAX 访问外部 Web 服务 [ExternalWS]。所以很明显,需要先创建本地代理服务[LocalProxyWS],然后再访问外部的web服务。现在,外部服务 web 方法 [Process] 基本上将我们网站上的当前页面重定向到他们的网站,做一些工作然后返回到我们的网站。
我想要什么:我希望当用户点击我们网站上的按钮(“进程”)时,它应该打开一个新窗口,然后开始在新窗口上执行请求,所以我可以让我的网站上的页面永久显示(它将每 15 秒向外部服务(通过本地代理)轮询一次请求以获取状态)。
希望我的解释清楚。
以下是我目前的代码,如果有其他有效的替代方法,请随时发表评论..
调用外部服务的本地代理服务如下..
[ServiceContract(Namespace = "LocalProxy")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class LocalProxyToExternalService
{
[OperationContract]
public void InitiateTransaction(string amount)
{
//NOTE: Basically want to call the external service from here in
a new window.....
//HttpContext.Current.Response.Redirect("www.google.com", false);
}
}
我的页面代码如下...
function PayWithXYZ() {
var newWindow = window.open('', '_blank', 'width=500,height=500', false);
newWindow.focus();
var service = new LocalProxy.LocalProxyToExternalService();
service.InitiateTransaction($('input[id*=TextBox1]').val()); //, OnPayWithXYZCompleted, OnPayWithXYZError);
}
function OnPayWithXYZCompleted(result) {
$('span[id*=Label1]').text(result);
}
function OnPayWithXYZError(result) {
alert(result.get_message());
}
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Services/LocalProxyToExternalService.svc" />
</Services>
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Pay with XYZ" OnClick="Button1_Click" />
<input id="Button2" type="button" value="Client Button" onclick="PayWithXYZ();" />
</div>
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="Label"></asp:Label>
基本上,我通过单击按钮打开一个新窗口,然后想在该新窗口中处理新请求,以便我可以从我网站上的当前页面向用户显示状态
到目前为止,它打开了新窗口,但没有将请求转移到该窗口,但我在 firebug 中收到如下错误消息...
【问题讨论】:
标签: javascript asp.net ajax wcf