Re: [問題] 新手請教jquery的get相關

看板Ajax作者 (-858993460)時間12年前 (2012/04/17 12:38), 編輯推噓3(300)
留言3則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《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
比較瞭解了!Thx
04/17 13:05, 1F

04/17 14:58, , 2F
server推wamp,三種驚奇一次滿足
04/17 14:58, 2F

04/17 18:30, , 3F
推 NodeJS XD 同是JavaScript
04/17 18:30, 3F
文章代碼(AID): #1FZFEikz (Ajax)
文章代碼(AID): #1FZFEikz (Ajax)