回答編集履歴
1
jQueryでGETリクエストをボディ無しとしていることの根拠を追記した。
answer
CHANGED
@@ -9,4 +9,31 @@
|
|
9
9
|
jQueryを使って、takatoさんの実現したいことはできなそうです。
|
10
10
|
|
11
11
|
xhrを直接使えば実現はできるのではないかと思いますが、
|
12
|
-
そもそも、なぜGETでjsonリクエストしたいのでしょうか?
|
12
|
+
そもそも、なぜGETでjsonリクエストしたいのでしょうか?
|
13
|
+
|
14
|
+
|
15
|
+
### jQueryでGETリクエストはボディ無しとしていることの根拠
|
16
|
+
[jQueryのリファレンス](http://api.jquery.com/jQuery.ajax/)のdataパラメータの説明を見ると、
|
17
|
+
> Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-request
|
18
|
+
|
19
|
+
とありdataの内容をurlに付加すると記述されています。
|
20
|
+
|
21
|
+
また、[jQueryのソース](https://github.com/jquery/jquery/blob/e077ffb083743f4a4b990f586c9d25d787e7b417/src/ajax.js)を見ると、以下の様に、GETとHEADの場合にはhasContentがfalseになる様に判定しています。
|
22
|
+
```lang-javascript
|
23
|
+
rnoContent = /^(?:GET|HEAD)$/,p
|
24
|
+
```
|
25
|
+
```lang-javascript
|
26
|
+
// Determine if request has content
|
27
|
+
s.hasContent = !rnoContent.test( s.type );
|
28
|
+
|
29
|
+
// Save the URL in case we're toying with the If-Modified-Since
|
30
|
+
// and/or If-None-Match header later on
|
31
|
+
// Remove hash to simplify url manipulation
|
32
|
+
cacheURL = s.url.replace( rhash, "" );
|
33
|
+
|
34
|
+
// More options handling for requests with no content
|
35
|
+
if ( !s.hasContent ) {
|
36
|
+
|
37
|
+
// Remember the hash so we can put it back
|
38
|
+
uncached = s.url.slice( cacheURL.length );
|
39
|
+
```
|