Introduction to the Information Systems
例: google サーチに
http://www.google.co.jp/search? にパラメータ
q=___
tbm=isch
などを渡す
有料もののや、アプリケーション登録を行って使う必要のあるものもある。
ローカルHTMLページにペタペタ貼り付けてみよう
$.ajax
という呼び方が一般的)と、$.getJSON
関数(jQueryの新しい機能)実例:郵便番号検索
doctype html
script src=src="https://code.jquery.com/jquery-3.1.1.min.js"
p
span zip:
input value="386-1298"
button go
#result
javascript:
function go() {
var zip=$('input').val()
console.log(`zip=${zip}`)
$.get(`http://zipcloud.ibsnet.co.jp/api/search?zipcode=${zip}`,(data)=>{
$('#result').textContent=data
})
}
$('button').click(go)
回避策として、$.get でなく $.getJSON を使うよう変更してみる。
$.getJSON(`http://zipcloud.ibsnet.co.jp/api/search?zipcode=${zip}&callback=?`,(data)=>{
var rslt=""
$.each(data.results, (i, item)=>{
var r=item.address1+item.address2+item.address3
rslt+=`<p>${r}</p>`
console.log(rslt)
$('#result').append(rslt)
})
})