Re: [問題] 新手請教jquery的get相關
※ 引述《poototo (poototo)》之銘言:
: 非本科自學,有點混淆,希望前輩解惑
: 1. .load()
: 是不是只用於將資料載入html5元素內,
: 就是 $(selector).load() 但不會有$.load()這種東西?
是的
: 2. .get .post .getJSON vs .ajax()
: 官網上都有寫 This is a shorthand Ajax function, which is equivalent to:
: 是指單純最後效果等價,還是幕後運作方式真的都是.ajax在跑?
是的
jQuery 的原始碼裡的確是這樣寫的:
http://nopaste.info/00d9a40bd6.html
(這是摘自我久遠之前抓的 1.4.4 版的原始碼,
不過這段應該不會在改版時變動太多, 所以也就放上來給你參考)
: 3. 以上是否都不能存取本機的檔案?
: 官網有範例如下,ajax/test.html我照路徑放本機,結果沒反應
: $.get('ajax/test.html', function(data) {
: $('.result').html(data);
: alert('Load was performed.');
: });
一般來說是不行的
但據說 Chrome 好像有辦法可以...
http://tinyurl.com/7ayb39h
通常解法則是↓在本機架站之後開 localhost 的檔案
: 4. 可以本機模擬server嗎?
請去找架站軟體
對新手來說最簡單的方法是去找 AppServ
: 5. 我在inline script內造json字串,再JSON.parse(json字串)這樣來讀
: 只是網路範例下每一行有「\」,我去掉就不行,有人這樣嗎?
: <script>
: var jsonString =
: '{\
: "one": "這是json data", \
: "two": "Beady little eyes", \
: "three": "Little birds pitch by my doorstep" \
: }';
: .......
: </script>
: 感恩!
你應該看得出來這整個是一個大字串
只是因為分成多行了所以必須要用 \ 來連接起來
大概就是像這個樣子吧:
var mystring = 'we have break this string\
into two pieces';
如果你覺得這樣不太清爽的話也可以寫成這樣:
var mystring = 'we have break this string' +
'into two pieces';
要注意的是
這樣接起來的時候會直接把換行吃掉接起來
也就是上面兩個例子都等於這樣:
var mystring = 'we have break this stringinto two pieces';
所以你有注意的話 那個 json 字串在每個元素後面會先有一個空白再加 \
就是防止東西全部黏成一團
--
'You've sort of made up for it tonight,' said Harry. 'Getting the
sword. Finishing the Horcrux. Saving my life.'
'That makes me sound a lot cooler then I was,' Ron mumbled.
'Stuff like that always sounds cooler then it really was,' said
Harry. 'I've been trying to tell you that for years.'
-- Harry Potter and the Deathly Hollows, P.308
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.230.62
推
04/17 13:05, , 1F
04/17 13:05, 1F
推
04/17 14:58, , 2F
04/17 14:58, 2F
推
04/17 18:30, , 3F
04/17 18:30, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):