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

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

將原型 Ajax POST 重建為“普通”js

將原型 Ajax POST 重建為“普通”js

慕娘9325324 2021-12-23 19:37:42
我需要的是通過javascript重建prototype.js Ajax請求。(沒有 jQuery / 沒有獲?。?。需要 IE 支持(出于某些原因...)new Ajax.Request(urlVar,{  method: 'post',  parameters: {elid: document.getElementById('element').selectedIndex},  onCreate: function(){    //do somethings  },  onComplete: fucnction (event){    currentValues = eval('(' + event.responseText + ')');    console.log(currentValues); // will give me an array with 3 objects  }});我嘗試過的是:var xhr = new XMLHttpRequest();xhr.open("POST", urlVar, true);xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");xhr.onreadystatechange = function (event) {   if (xhr.readyState == 4) {      if (xhr.status == 200) {         currentValues = eval('(' + event.responseText + ')');         console.log(currentValues); // i see an error that "currentValues" is undefined         //i can get 1 object if i will do eval('(' + THIS.responseText + ')');         // but it still bugs me a lot..         //other actions here      }      else if (xhr.status == 400) {         console.log('ERROR')      }      else {         console.log('something else other than 200 was returned');      }   }}xhr.send(document.getElementById('element').selectedIndex);也許有人知道在這種情況下哪種結構會起作用。有什么方法可以通過 js 執行 onCreate / onComplete 嗎?
查看完整描述

1 回答

?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

使用this.responseTextxhr.responseText(與您已經訪問.status和的方式相同.readyState)或event.target.responseText。在event不具有responseText本身。


查看完整回答
反對 回復 2021-12-23
  • 1 回答
  • 0 關注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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