我(尝试)在这里学习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