我建立了一个基本的客户端回调到WCF服务。请参阅以下示例代码。页面基于ajax客户端回调重新加载到WCF
使用连接到资源管理器,你可以看到一个http过滤器查看时: 1. service1.svc/JS工作正常,并返回正确的Java脚本的浏览器 2. serrvice1.svc作品,并返回一个适当的JSON数据。 3.电话很好,使用警报,而不是更新div信息我得到的数据。
但是之后在警报之后确定页面然后从头开始重新加载。
不知道为什么?有什么想法?
代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Simple_ClientNetwork_Calls.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body >
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/WebKit.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="~/Service1.svc" />
</Services>
</asp:ScriptManager>
<script type="text/javascript">
var BedList = null;
var status = null;
//add a window.load handler to init any necessary controls
Sys.Application.add_load(initializeControls);
function initializeControls(e) {
status = $get("status");
}
function testme() {
document.bgColor = "#FF0000";
getBedList();
}
function getBedList() {
iMDsoft.Demo.SimpleService.GetBedList(GetBedListOnSuccess, GetBedListOnFailed);
}
function GetBedListOnSuccess(results, context, methodName) {
var BedList = results
status.innerText = "Complete" + BedList[0].Name;
}
function GetBedListOnFailed(results, context, methodName) {
status.innerText = "GetBedListOnFailed: " + results.get_message();
}
</script>
<button id="button1" onclick="testme();" >TestMe</button>
<div id="status">
</div>
</div>
</form>
</body>
</html>
是的,这做到了。 你能解释一下背后的逻辑吗? – Eyal 2010-02-20 14:31:17
返回false指示事件取消。再一次,我不记得按钮是如何工作的,但我想通常点击一个按钮会回复表单。通过返回false,你基本上告诉按钮不要做它通常做的事情。 – CodingInsomnia 2010-02-20 15:41:59