English 中文(简体)
我如何从AJAX-enabled WCF服务公司(ASP.Net)获得文物?
原标题:How do I get return object properties from an AJAX-enabled WCF service (ASP.Net)?
  • 时间:2012-01-13 22:10:21
  •  标签:
  • ajax
  • wcf
  • json

我设立了非洲宇宙航空研究开发机构,负责归还一个清单和编号;以及一个定制类别I。 我可以拿到数据回来,但我不知道如何获得我那类财产价值。

在这里,我要说:

[Serializable]
public class Favorite
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Url { get; set; }
}

在此,我的妇女和家庭论坛服务:

[OperationContract]
    public List<Favorite> GetFavorites()
    {
        MembershipUser thisUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
        int userId = (int)thisUser.ProviderUserKey;
        return GetFavorites(userId);
    }

该处的配置:

<system.serviceModel>
<services>
  <service name="MySvc">
    <endpoint address="" behaviorConfiguration="MySvcEndpointBehavior"
              binding="webHttpBinding"
              contract="MySvc" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="MySvcEndpointBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

这里是我实际上称职的 j:

$.ajax({
    type: "POST",
    url: "MySvc.svc/GetFavorites",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (result) {
        var favs = result.d;
    }
});

在我的“ava”中,我可以称之为“favs.length”,这给我带来了适当的成果。 但例如,如果我试图进入“favs[0]。 标题,我收到“未界定”的信息。 谁能帮助我?

最佳回答

仅使用青少年。

success: function (result) {

// log
console.log(result);

// dir
console.dir(result);

// iterating through an object s properties in JS

for(var i = 0; i < favs.length; i++){
    for(property in favs[i]){
        console.log(property + ": " + favs[i][property]);
    }
}

};
问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签