Learner,請求戰術指導,前面那個bind是什么方法?還有get([],function(){},"json")后面那個json是怎么用?
?$(function?()?{ ????????????????$("#btnShow").bind("click",?function?()?{ ????????????????????var?$this?=?$(this); ????????????????????$.get("http://www.xianlaiwan.cn/data/info_f.php",function(data)?{ ????????????????????????$this.attr("disabled",?"true"); ????????????????????????$("ul").append("<li>我的名字叫:"?+?data.name?+?"</li>"); ????????????????????????$("ul").append("<li>男朋友對我說:"?+?data.say?+?"</li>"); ????????????????????},?"json"); ????????????????}) ????????????});
2017-08-04
查jq的文檔。
$.get( url [, data ] [, success ] [, dataType ] )?
dataType指從服務器返回的預期的數據類型。默認:xml, json, script, text,html。 所以才寫json
2017-08-04
bind()和on()一樣是綁定事件,告訴瀏覽器在鼠標點擊時候要做什么。?
你換成on()也是一樣的。 ?
再來就是而后面的json。
回調函數function(data,status,xhr){} 一般里面有三個參數。
data就是獲取請求的數據,?
status就是請求的狀態,比如測試里面點擊后,出現了ul列表。
而xhr就是數據對象的類型。因為是JSON 結構定義的數組,數據類型是json格式, 所以加上才能獲取數據。
2017-08-03
http://www.runoob.com/jquery/event-bind.html
http://www.runoob.com/json/json-tutorial.html