未定义对象 Jquery/javascript
Undefined Object Jquery/javascript
我正在尝试找出 Eventbrite api 并且我已经找到了一些可以工作的东西,但不是我想要的。
下面是我的代码。第一个脚本有效。第二个没有并产生此错误:102TypeError: undefined is not an object (evaluating 'data.name.text')
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.eventbriteapi.com/v3/events/17920884849/?token=NR4COIXFSOYKGDDG6MSP",
"method": "GET",
"headers": {}
}
$.ajax(settings).done(function (data) {
console.log(data);
var content = "<h2>" + data.name.text + "</h2>" + data.description.html;
jQuery("#eventbrite").append(content);
});
</script>
<div id="eventbrite"></div>
<h1>Another test</h1>
<script>
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.eventbriteapi.com/v3/organizers/12748782127/events/?token=ZMDFKJWCHAMX5WFVPBAJ",
"method": "GET",
"headers": {}
}
jQuery.ajax(settings).done(function (data) {
console.log(data);
var content = "<h2>" + data.name.text + "</h2>" + data.description.html;
jQuery("#eventbrite2").append(content);
});
</script>
<div id="eventbrite2"></div>
谢谢。
查看返回的 JSON。
第一个调用看起来像这样,所以 data.name
工作正常:
{
"name": {
"text": "An Aggressive Approach to Concise Writing, with Joe Welinske",
"html": "An Aggressive Approach to Concise Writing, with Joe Welinske"
},
第二个调用看起来像这样,所以您需要 data.events[0].name.text
:
{
"pagination": {
"object_count": 1,
"page_number": 1,
"page_size": 50,
"page_count": 1
},
"events": [
{
"name": {
"text": "Test Event 1",
"html": "Test Event 1"
我正在尝试找出 Eventbrite api 并且我已经找到了一些可以工作的东西,但不是我想要的。
下面是我的代码。第一个脚本有效。第二个没有并产生此错误:102TypeError: undefined is not an object (evaluating 'data.name.text')
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.eventbriteapi.com/v3/events/17920884849/?token=NR4COIXFSOYKGDDG6MSP",
"method": "GET",
"headers": {}
}
$.ajax(settings).done(function (data) {
console.log(data);
var content = "<h2>" + data.name.text + "</h2>" + data.description.html;
jQuery("#eventbrite").append(content);
});
</script>
<div id="eventbrite"></div>
<h1>Another test</h1>
<script>
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.eventbriteapi.com/v3/organizers/12748782127/events/?token=ZMDFKJWCHAMX5WFVPBAJ",
"method": "GET",
"headers": {}
}
jQuery.ajax(settings).done(function (data) {
console.log(data);
var content = "<h2>" + data.name.text + "</h2>" + data.description.html;
jQuery("#eventbrite2").append(content);
});
</script>
<div id="eventbrite2"></div>
谢谢。
查看返回的 JSON。
第一个调用看起来像这样,所以 data.name
工作正常:
{
"name": {
"text": "An Aggressive Approach to Concise Writing, with Joe Welinske",
"html": "An Aggressive Approach to Concise Writing, with Joe Welinske"
},
第二个调用看起来像这样,所以您需要 data.events[0].name.text
:
{
"pagination": {
"object_count": 1,
"page_number": 1,
"page_size": 50,
"page_count": 1
},
"events": [
{
"name": {
"text": "Test Event 1",
"html": "Test Event 1"