亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

解決TypeError:事件未定義

解決TypeError:事件未定義

素胚勾勒不出你 2021-05-10 09:10:54
我正在嘗試使用用戶的郵政編碼來請求該地區的代表。為了進行故障排除,我嘗試記錄郵政編碼和包含郵政編碼的URL的控制臺。$(document).ready(function() {      //Wait until user submits postal code (ie. K2H6G7)      $("form").on("submit", function(event) {          var request = new XMLHttpRequest();          event.preventDefault();          var searchWord = $("#search").val(); //Take postalcode and apply to url          var url = "https://represent.opennorth.ca/postcodes/" + searchWord + "/?format=apibrowser";          console.log(searchWord);          console.log(url) request.open('GET', url, true);          request.onreadystatechange = function() {            if (request.readyState === 4) {              if (request.status === 200) {                //Connect to API, create cards for each politician instance                var data = JSON.parse(this.response);                data.representatives_centroid.forEach(representatives_centroid => {                  const card = document.createElement('div');                  card.setAttribute('class', 'card');                  const img = document.createElement('img');                  img.src = representatives_centroid.photo_url;                  const p1 = document.createElement('p');                  p1.textContent = `$ {              representatives_centroid.party_name            }            $ {              representatives_centroid.elected_office            }            $ {              representatives_centroid.first_name            }            $ {              representatives_centroid.last_name            }            `                  const p2 = document.createElement('p');                  p2.textContent = `$ {              representatives_centroid.district_name            }            ` //Add data to card                  container.appendChild(card);                  card.appendChild(img);                  card.appendChild(p1);                  card.appendChild(p2);                });              } else {  我收到的錯誤消息是“ TypeError:事件未定義”。我缺少明顯的東西嗎?
查看完整描述

2 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

我不確定,但是在表格中輸入什么呢?


type =“ text”用于輸入,我想您需要一個action =“ / route /”類型的instate才能發生事件并可以阻止它。

問候。-


查看完整回答
反對 回復 2021-05-13
  • 2 回答
  • 0 關注
  • 259 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號