第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

JSON語法的問題,如何理解for循環(huán)那里

JSON語法的問題,如何理解for循環(huán)那里

滴答滴滴答滴 2016-12-12 11:25:27
<!DOCTYPE html><html lang="en"><head> ? ?<meta charset="UTF-8"> ? ?<title>task_24_01</title></head><body><button id="btn">點我</button><script> ? ?function ajax (opts) { ? ? ? ?var xhr = new XMLHttpRequest () ? ? ? ?xhr.onreadystatechange = function () { ? ? ? ? ? ?if (xhr.readyState === 4 && xhr.status === 200) { ? ? ? ? ? ? ? ?var json = JSON.parse(xhr.responseText); ? ? ? ? ? ? ? ?opts.success(json) ? ? ? ? ? ?} ? ? ? ? ? ?if (xhr.readyState === 4 && xhr.status === 404) { ? ? ? ? ? ? ? ?opts.error() ? ? ? ? ? ?} ? ? ? ?}; ? ? ? ?var dataStr = ""; ? ? ? ?for (var key in opts.data) { ? ? ? ? ? ?dataStr += key + '=' + opts.data[key] + '&' } ? ? ? ?dataStr = dataStr.substr(0, dataStr.length - 1); ? ? ? ?if (opts.type.toLowerCase() === 'get') { ? ? ? ? ? ?xhr.open(opts.type, opts.url + '?' + dataStr, true); ? ? ? ? ? ?xhr.send() ? ? ? ?} ? ? ? ?if(opts.type.toLowerCase() === 'post') { ? ? ? ? ? ?xhr.open(opts.type, opts.url, true); ? ? ? ? ? ?xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ? ? ? ? ? ?xhr.send(dataStr) ? ? ? ?} ? ?} ? ?document.querySelector('#btn').addEventListener('click', function(){ ? ? ? ?btn = document.querySelector('#btn'); ? ? ? ?btn.innerHTML = '正在打印'; ? ? ? ?ajax({ ? ? ? ? ? ?url: 'getData.php', ? //接口地址 type: 'get', ? ? ? ? ? ? ? // 類型, post 或者 get, data: { ? ? ? ? ? ? ? ?username: 'xiaoming', ? ? ? ? ? ? ? ?password: 'abcd1234' }, ? ? ? ? ? ?success: function(ret){ ? ? ? ? ? ? ? ?console.log(ret); ? ? ? // {status: 0} btn.innerHTML = '點我' }, ? ? ? ? ? ?error: function(){ ? ? ? ? ? ? ? ?console.log('出錯了'); ? ? ? ? ? ? ? ?btn.innerHTML = '點我' } ? ? ? ?}) ? ?});</script></body></html>
查看完整描述

3 回答

?
一瞬兒光

TA貢獻178條經(jīng)驗 獲得超70個贊

這都是啥東西?

查看完整回答
反對 回復(fù) 2016-12-12
  • 3 回答
  • 1 關(guān)注
  • 1707 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號