作者LPH66 (-858993460)
看板Ajax
标题Re: [问题] 新手请教jquery的get相关
时间Tue Apr 17 12:38:01 2012
※ 引述《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
1F:推 poototo:比较了解了!Thx 04/17 13:05
2F:推 Qiqi:server推wamp,三种惊奇一次满足 04/17 14:58
3F:推 hanhong:推 NodeJS XD 同是JavaScript 04/17 18:30