我(嘗試)在這裏學習javascript,jquery和knockout。我終於得到了一個web服務發送回JSON。但我無法顯示數據。有人能告訴我爲什麼這不起作用嗎?沒有錯誤被拋出。一旦運行,表單中沒有任何內容。標題說明了一切:它不起作用,沒有解釋發生了什麼。我需要知道爲什麼不。爲什麼不這js/jquery/knockout工作?
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="EditLTC2.aspx.cs" Inherits="RaterWeb.EditLTC2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="formLayout">
<label for="txtInsuredName">Insured Name:</label>
<input data-bind="value: InsuredName" />
</div>
<script>
$(document).ready(function()
{
var self = this;
// Load selected quote from the JSON service
SelQuote = $.getJSON("http://localhost:46648/LTCJSON.svc/getLTCWithIDs/4/");
// assign to AppViewModel
function AppViewModel()
{
this.InsuredName = ko.observable(SelQuote.InsuredName);
}
ko.applyBindings(new AppViewModel());
});
</script>
</asp:Content>
'$ .getJSON'是異步的。 – elclanrs
...並且它不返回它提取的數據。它返回一個承諾對象。 – Pointy
** **的DUP:http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call – elclanrs