我建立了一個基本的客戶端回調到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