gpt4 book ai didi

javascript - 在 JavaScript 中迭代 MooTools JSONP 输出

转载 作者:行者123 更新时间:2023-12-02 20:27:57 25 4
gpt4 key购买 nike

我一直在尝试名为 Agatha 的 .NET WCF 请求/响应框架。他们的示例之一是使用 MooTools 调用 JSONP 扩展,然后在 ASP.NET MVC 应用程序的页面中显示结果。

我修改了一个示例,该示例返回单个字符串来调用我创建的服务,该服务返回客户集合(来自 AdventureWorks 数据库)。

一般来说,我对 JavaScript 的经验很少,并且我一直在创建一个将从服务中获取输出的函数:

Request.JSONP.request_map.request_0({"ProcessJsonRequestsResult":[{"__type":"GetCustomerDetailsResponse:#Reference.ServiceLayer.Common.AdventureWorks.RequestAndResponse","Exception":null,"ExceptionType":0,"IsCached":false,"Customers":[{"CompanyName":"Trailblazing Sports","CustomerId":187,"FirstName":"Frank","LastName":"Campbell","MiddleName":null},{"CompanyName":"Authorized Bike Sales and Rental","CustomerId":199,"FirstName":"Roger","LastName":"Lengel","MiddleName":null},{"CompanyName":"Westside Plaza","CustomerId":599,"FirstName":"Raul","LastName":"Casts","MiddleName":"E."},{"CompanyName":"Westside Plaza","CustomerId":29641,"FirstName":"Raul","LastName":"Casts","MiddleName":"E."},{"CompanyName":"Trailblazing Sports","CustomerId":29938,"FirstName":"Frank","LastName":"Campbell","MiddleName":null},{"CompanyName":"Authorized Bike Sales and Rental","CustomerId":29942,"FirstName":"Roger","LastName":"Lengel","MiddleName":null}]}]});

并允许我迭代它,以便我可以将结果输出到页面中。有人能指出我正确的方向吗?

最佳答案

@pleasedontbelong:使用 JSONP,您不必使用 JSON.decode

@John Kattenhorn:您应该使用 onComplete 事件,如文档中的示例:http://mootools.net/docs/more/Request/Request.JSONP

// ...

onComplete: function(data){
// You can, for example, iterate over the data
// Assuming you have MooTools 1.3
Object.each(data, function(value, key){

});
}

// ...

这就是您应该如何使用数据,Request.JSONP.request_map.request_0 变量也是私有(private)的。

关于javascript - 在 JavaScript 中迭代 MooTools JSONP 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4555167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com