TypeError: a is not an Object. (evaluating '"length"in a')
というエラーが表示されています。処理はAjax経由でDBの値を取得するというものなんですが、aというのが見当たりません。
これはaいうメソッドをどこかで作成してしまったのでしょうか。
ちなみにAjaxの処理自体は成功しています。
これがコードです。
JS
1$(function() { 2 var array = []; 3 var hotel = null; 4 var process = null; 5 var top = 0; 6 var normaltop = 0; 7 var sorttop = 0; 8 var normalFlag = false; 9 var sortflag = false; 10 11 function hotelClone() { 12 var hotel = $("<div>", { 13 "class": "hotel" 14 }); 15 var hotelpics = $("<div>", { 16 "class": "hotelpics" 17 }); 18 var mainpic = $("<div>", { 19 "class": "mainpic" 20 }); 21 var others = $("<div>", { 22 "class": "others" 23 }); 24 var hotelinfo = $("<div>", { 25 "class": "hotelinfo" 26 }); 27 var hotelname = $("<a>", { 28 "class": "hotelname" 29 }); 30 var tags = $("<div>", { 31 "class": "tags" 32 }); 33 var rating = $("<div>", { 34 "class": "rating" 35 }); 36 var rateposition = $("<span>", { 37 "class": "rateposition" 38 }); 39 var price = $("<div>", { 40 "class": "price" 41 }); 42 var clear = $("<div>", { 43 "class": "clear" 44 }); 45 46 hotelpics.append(mainpic, others); 47 rating.append(rateposition); 48 hotelinfo.append(hotelname, tags, rating, price); 49 result = hotel.append(hotelpics, hotelinfo, clear); 50 return result; 51 }; 52 53 function getHotels(process, top) { 54 return $.post('ajax.php', { 55 word: word, 56 kind: 'hotels', 57 process: process, 58 top: top 59 }); 60 }; 61 62 function getPics() { 63 return $.post('ajax.php', { 64 word: word, 65 kind: 'pics' 66 }); 67 }; 68 69 function getTags() { 70 return $.post('ajax.php', { 71 word: word, 72 kind: 'tags' 73 }); 74 }; 75 76 function getRates() { 77 return $.post('ajax.php', { 78 word: word, 79 kind: 'rate' 80 }); 81 }; 82 83 function displayHotels(process) { 84 // if (process === 'normal') { 85 // normalFlag = true; 86 // sortflag = false; 87 // top = normaltop; 88 // } else if (process === 'sortbyprice') { 89 // sortflag = true; 90 // normalFlag = false; 91 // top = sorttop; 92 // } 93 getHotels(process, 0).done(function(result) { 94 hotels = result; 95 console.log(hotels) 96 // if (hotels.length > 0) { 97 // if (normalFlag === true) { 98 // normaltop = normaltop + hotels.length; 99 // } else if (sortflag === true) { 100 // sorttop = sorttop + hotels.length; 101 // } 102 103 getPics().done(function(result) { 104 hotelpics = result; 105 106 getTags().done(function(result) { 107 hoteltags = result; 108 109 getRates().done(function(result) { 110 hotelrates = result; 111 112 var hotelsClone = []; //これから表示するホテルが入る 113 var hotelName = null; 114 var href = null; 115 var hotelMainPic = null; 116 var others1 = null; 117 var others2 = null; 118 var others3 = null; 119 var tags = []; 120 var rateWord = null; 121 var rate = null; 122 var price = null; 123 124 $.each(hotels, function(hotelindx, hotel) { 125 hotelsClone.push(hotelClone()); 126 hotelName = hotel.hotel_name; 127 href = 'about.php?hotelid=' + hotel.hotel_id + '&countrycode=' + hotel.country_code; 128 hotelsClone[hotelindx].find('.hotelname').append(hotelName); 129 hotelsClone[hotelindx].find('.hotelname').attr('href', href); 130 131 tags = []; 132 $.each(hoteltags, function(index, hoteltag) { 133 if (hotel.hotel_id === hoteltag.hotel_id && hotel.country_code === hoteltag.country_code) { 134 tags.push(hoteltag.tag); 135 } 136 }); 137 138 for (var i = 0; i < tags.length; i++) { 139 hotelsClone[hotelindx].find('.tags').append('<span>' + tags[i]); 140 } 141 142 price = hotel.price + '/1泊(1人)'; 143 $.each(hotelrates, function(index, hotelrate) { 144 if (hotel.hotel_id === hotelrate.hotel_id && hotel.country_code === hotelrate.country_code) { 145 rateWord = hotelrate.ratingresult 146 rate = hotelrate.rate; 147 hotelsClone[hotelindx].find('.rating .rateposition').append('<span>' + rateWord); 148 hotelsClone[hotelindx].find('.rating .rateposition').append('<span class="rate">' + rate); 149 } 150 }); 151 hotelsClone[hotelindx].find('.price').append('<span>' + price); 152 153 $.each(hotelpics, function(index, hotelpic) { 154 if (hotel.hotel_id === hotelpic.hotel_id && hotel.country_code === hotelpic.country_code) { 155 hotelMainPic = '<img' + ' src' + '="' + 'imgs/' + hotelpic.main_pic + '">'; 156 others1 = '<img' + ' src' + '="' + 'imgs/' + hotelpic.others1 + '">'; 157 others2 = '<img' + ' src' + '="' + 'imgs/' + hotelpic.others2 + '">'; 158 others3 = '<img' + ' src' + '="' + 'imgs/' + hotelpic.others3 + '">'; 159 hotelsClone[hotelindx].find('.mainpic').append(hotelMainPic); 160 hotelsClone[hotelindx].find('.others').append(others1); 161 hotelsClone[hotelindx].find('.others').append(others2); 162 hotelsClone[hotelindx].find('.others').append(others3); 163 } 164 }); 165 hotelsClone[hotelindx].find('.mainpic img').height(300).width(300); 166 hotelsClone[hotelindx].find('.others img').height(85).width(85); 167 }); 168 for (var i = 0; i < hotelsClone.length; i++) { 169 $('.mainrequirements').after(hotelsClone[i]); 170 } 171 hotelsClone = []; 172 top = 0; //念の為初期化 173 }); 174 }); 175 }); 176 // } 177 }); 178 } 179 180 //最初の処理 181 displayHotels('normal'); 182 183 184 //ここからクリック処理 185 $('#sortbyprice').on('click', function() { 186 if (!$(this).hasClass('selected')) { 187 $('mainrequirement').removeClass('selected'); 188 $(this).addClass('selected'); 189 process = $(this).attr('id'); 190 $('.hotel').remove(); 191 displayHotels(process); 192 return false; 193 } 194 }); 195 196 //ここからスクロール処理 197 $(window).on('scroll', function() { 198 if ((normaltop + sorttop) % 5 === 0) { 199 var doch = $(document).innerHeight(); //ページ全体の高さ 200 var winh = $(window).innerHeight(); //ウィンドウの高さ 201 var bottom = doch - winh; //ページ全体の高さ - ウィンドウの高さ = ページの最下部位置 202 203 if (bottom <= $(window).scrollTop()) { 204 //一番下までスクロールした時に実行 205 if (normalFlag === true) { 206 displayHotels('normal'); 207 } else if (sortflag === true) { 208 displayHotels('sortbyprice'); 209 } 210 } 211 } 212 }); 213}); 214
回答1件
あなたの回答
tips
プレビュー