我需要什么
jquery代码
$.ajax({
type: "GET",
contentType: 'application/json; charset=utf-8',
url: "http://local.10times.com/app.php/ajax?for=speakers&id="+id,
dataType: 'json',
async: true,
cache: false,
success: function(html)
{
var i=0;
$.each(html, function(i, obj) {
//use obj.id and obj.name here, for example:
console.log(obj[0].metadata.summary);
var obj1=obj[i].metadata.summary;
i++;
alert(obj1);// undefined
$(".speakers").append(obj[0].metadata.summary);
i++;
});
}
});
输出
0: Objectmetadata: Objectsummary: "Raj is the founder of GSF Accelerator, India’s first multi-city Tech Accelerator, backed by 20 iconic Digital founders and 5 leading venture funds frversaw (as President, Reliance E".
json string
data: [
{
metadata: {
summary: "Rajesh is the founder of GSF Accelerator, India’s first multi-city Tech Accelerator, backed by 20 iconic Digital founders and 5 leading venture funds from across the world. Rajesh is also the founder of GSF Superangels network and curator of the Global Superangels Forum. He is the co-host and curator of Founders Forum India. Rajesh has made over 15 investments as an active and engaged angel investor.His journey has been a continuum of re-invention waves. In the first wave, he brought private radio (Times FM) to India in early nineties, and redefined Indian youth culture. In his second wave, he was at the cusp of early Internet culture in India and built Indiatimes.com, the most valuable Internet business in India in 2005 (funded by Sequoia). In the third wave, Rajesh was at the centre of a massive transformation of the Indian film industry, where he oversaw (as President, Reliance Entertainment) the corporatization of mom and pop Bollywood businesses into multi-billion dollar enterprise. At Reliance, Rajesh found himself at the centre of cross-border investment and alignment between Hollywood and Indian Film Industry and one of the biggest investment deals (DreamWorks) in Hollywood. Currently in his fourth wave, Rajesh is building the vital building blocks of a nascent early stage startup ecosystem in India, and sees this as the biggest and most exciting challenge that he has faced in his life.Rajesh is an alumnus of Harvard Business School (AMP), and has a fellowship from London School of Economics. Twitter URL: http://twitter.com/rajeshsawhneyWebsite: www.gsfindia.com"
}
},
{
metadata: {
summary: "Building and scaling businesses focused on simple yet powerful consumer products has been the dream, and this has come to life both at Skype, Gumtree and now most recently at LimeRoad.com. We are the the start of the journey to build the most extensive and engaging lifestyle platform ever. Our sole objective is to make the discovery experience on LimeRoad so delightful, that we become the online destination to find gorgeous yet affordable products.Earlier, with 13m users at Gumtree, we built UK's largest horizontal classifieds business. In c. two years, we went from a No. 3 position to market leading positions in jobs and consumer-to-consumer car sales, growing visits by 35% y-o-y in the UK (marketing spend remaining unchanged). Gumtree required transformational leadership, and I spent the better part of my time there scaling team capabilities, product, sales, marketing and CS functions, whilst re-architecting the financials towards core revenue streams.Prior to this, Skype was a powerful leadership development experience - being part of the executive management team of a high growth technology company, transitioning from founder–led-startup with 3 CEO changes in 2 years, whilst also building the most dramatic upgrade of the product. What a roller coaster, but not one to trade out of!Specialties: Scaling businesses, by setting direction and managing execution around product development, marketing, sales and operations. Building and empowering high performing teams."
}
},
{
metadata: {
summary: "I have led various design projects providing better browsing experience for users and helping businesses increase their conversion rates. I have experience in strategising and conceptualising designs for various domains like Ecommerce, Social Networking sites, Web based intranets, Banking and finance applications etc. I have helped companies look at their web logs and usage data to interpret user behaviour. I has keen interest in designing for the new age internet industry. I have been closely following the change in users and their online behaviours.I also specialise in conducting User researches and Usability tests across various domains and cultures.I have led several contextual innovation projects for companies like Intel, HP, GE etc conducting researches in emerging markets of India and China and innovating products catering to these markets. I have also performed Usability tests for websites, desktop applications, mobile phone devices for companies like Nokia, AOL, Vodaphone, Australian government websites and several Indian websites. I have experience in conducting Remote Usability Testing as well.I am a co founder of Techved Design which is a User Experience consultancy in Mumbai. The consultancy helps clients understand user behaviour and provide solutions based on User Centred Design Methodology. It also conducts workshops to train people on principles of Usability. Techved Design has also partnered with consultancies in China and Australia to provide a suite of services across the Asia Pacific region."
}
},
{
metadata: {
summary: "Goal oriented engineering executive with keen eye on execution, organizational efficiency and long term strategy, developing enterprise class eCommerce Marketplace Platform at the Fastest Growing eCommerce Marketplace in India - ShopClues.com.What makes this possible:• Extensive experience in developing highly scalable Consumer Internet technologies (like ecommerce platforms, Content Delivery, etc.)• Create and Manage rockstar team focused in skills, organizational efficiency, process optimization for delivering world class products at lightning speed.• Collaborate with all lines of business, solution providers, technologists and thought leaders.• Finally, build a culture and work environment that is goal driven, empower and reward individuals for accomplishing the impossibles.• I love what I do.Specialties: • Application & Enterprise Solutions • Product Strategy and direction• Product Architecture• Engineering Management (Fortune 100 & Startups)• Project Management• Process Improvement• On-Time Product Delivery • Product Design, Development , Quality & UsabilityIndustry experience:• Consumer Marketing - Social, Local & Mobile.• eCommerce platforms & eCommerce Marketplace platforms• Customer Relationship Management• Data Loss and Prevention - Data security• Software-as-a-Service SaaS"
}
},
输出
问题我有
的console.log(OBJ [0] .metadata.summary);我得到第一个json字符串索引。
but while iterating loop Uncaught TypeError: Cannot read property 'metadata' of undefined.
答案 0 :(得分:0)
试试这个
//Ajax Done catch JSON from PHP
request.done(function(dataset){
for (var index in dataset){
dataPHPtoJsJS=dataset[index].metadata.summary;
}
}
答案 1 :(得分:-1)
尝试 的console.log(OBJ [0] .Objectmetadata.Objectsummary) 它会起作用
答案 2 :(得分:-1)
不需要额外的i变量,$ .each已经为你提供了索引。
$.each(html.data, function (index, obj) {
//use obj.id and obj.name here, for example:
console.log(obj.metadata.summary, $(".speakers"));
$(".speakers").append('<div class="speaker">' + obj.metadata.summary + '</div>');
});
答案 3 :(得分:-1)
你得到的问题你正在直接访问你的json循环。
首先将JSOn数据解码为数组,如下所示
$数据= json_decode($数据,TRUE);
然后将其添加到foreach循环
foreach ($data as $key => $value)
{
}
现在循环访问您的数据。希望这对你有用。