質問編集履歴
4
誤った表記
title
CHANGED
File without changes
|
body
CHANGED
@@ -117,8 +117,6 @@
|
|
117
117
|
```PHP
|
118
118
|
<?php
|
119
119
|
|
120
|
-
<?php
|
121
|
-
|
122
120
|
header("Content-type: application/json; charset=utf-8");
|
123
121
|
if(isset($_POST['request'])){
|
124
122
|
echo json_encode("OK");
|
3
errorThrown:SyntaxError:Unexpected token O
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,28 +2,14 @@
|
|
2
2
|
monacaとOnsenUIを使って同一ディレクトリから取り出したtextをチェックボックスに入れてチェックした値をサーバーに渡すというプログラムを作っていますが、サーバーに渡す部分で詰まってしまいました。
|
3
3
|
ソースコードを乗せましたのでおかしなところを指摘していただけないでしょうか。
|
4
4
|
よろしくおねがいします。
|
5
|
-
サーバーはローカル開発環境でXAMPPを使っています。
|
6
5
|
当方、PHP、Ajaxをほとんど触ったことがないためわかりやすい解説をお願いします。
|
7
6
|
|
8
7
|
###発生している問題・エラーメッセージ
|
9
|
-
XMLHttpRequest.status:
|
8
|
+
XMLHttpRequest.status:200
|
9
|
+
XMLHttpRequest.responseText:OK
|
10
|
+
textStatus:textStatus:parsererror → phpの戻り値がjson形式になっていなかったことが原因
|
11
|
+
errorThrown:SyntaxError:Unexpected token O
|
10
12
|
|
11
|
-
XMLHttpRequest.responseText:<html>
|
12
|
-
<head><tittle>404 Not Found</title></head>
|
13
|
-
<body bgcolor="white">
|
14
|
-
<center><h1>404 Not Found</h1></center>
|
15
|
-
<hr><center>nginx</center>
|
16
|
-
</body>
|
17
|
-
</html>
|
18
|
-
<!--a padding to disable MSIE and Chrome friendly error page -->
|
19
|
-
<!--a padding to disable MSIE and Chrome friendly error page -->
|
20
|
-
<!--a padding to disable MSIE and Chrome friendly error page -->
|
21
|
-
<!--a padding to disable MSIE and Chrome friendly error page -->
|
22
|
-
<!--a padding to disable MSIE and Chrome friendly error page -->
|
23
|
-
<!--a padding to disable MSIE and Chrome friendly error page -->
|
24
|
-
|
25
|
-
textStatus:error
|
26
|
-
|
27
13
|
errorThrown:OK
|
28
14
|
###ソースコード
|
29
15
|
```HTML
|
@@ -75,12 +61,12 @@
|
|
75
61
|
chkVal.push($(this).val());
|
76
62
|
});
|
77
63
|
|
78
|
-
var data = chkVal
|
64
|
+
var data = {'recuest':JSON.stringify(chkVal)};
|
79
65
|
|
80
66
|
$.ajax({
|
81
67
|
type:"post",
|
82
68
|
url:"/php/sample/send.php",
|
83
|
-
data:
|
69
|
+
data:data,
|
84
70
|
crossDomain: true,
|
85
71
|
dataType:"json",
|
86
72
|
scriptCharset: "utf-8",
|
@@ -135,7 +121,7 @@
|
|
135
121
|
|
136
122
|
header("Content-type: application/json; charset=utf-8");
|
137
123
|
if(isset($_POST['request'])){
|
138
|
-
echo "OK";
|
124
|
+
echo json_encode("OK");
|
139
125
|
}
|
140
126
|
else{
|
141
127
|
echo 'The parameter of "request" is not found.';
|
@@ -144,4 +130,12 @@
|
|
144
130
|
?>
|
145
131
|
```
|
146
132
|
|
147
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
133
|
+
###補足情報(言語/FW/ツール等のバージョンなど)
|
134
|
+
|
135
|
+
liplyさんのおっしゃったとおりチェックしていった結果クロスドメイン制約に引っかかっていたためサーバーと通信できていませんでした。
|
136
|
+
なので新しくサーバーを都合したところXMLHttpRequest.status:200となり、通信することができました。
|
137
|
+
|
138
|
+
ですがtextStatusとerrorThrownがエラーになってしまい、textStatusのほうは自力で解決できたのですが、errorThrownのほうが解決できません。
|
139
|
+
もう一度お力をお貸ししていただけないでしょうか・・・
|
140
|
+
よろしくお願いします。
|
141
|
+
errorThrown:SyntaxError:Unexpected token O
|
2
エラーを変更しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,8 +7,23 @@
|
|
7
7
|
|
8
8
|
###発生している問題・エラーメッセージ
|
9
9
|
XMLHttpRequest.status:404
|
10
|
+
|
10
|
-
XMLHttpRequest.responseText:
|
11
|
+
XMLHttpRequest.responseText:<html>
|
12
|
+
<head><tittle>404 Not Found</title></head>
|
13
|
+
<body bgcolor="white">
|
14
|
+
<center><h1>404 Not Found</h1></center>
|
15
|
+
<hr><center>nginx</center>
|
16
|
+
</body>
|
17
|
+
</html>
|
18
|
+
<!--a padding to disable MSIE and Chrome friendly error page -->
|
19
|
+
<!--a padding to disable MSIE and Chrome friendly error page -->
|
20
|
+
<!--a padding to disable MSIE and Chrome friendly error page -->
|
21
|
+
<!--a padding to disable MSIE and Chrome friendly error page -->
|
22
|
+
<!--a padding to disable MSIE and Chrome friendly error page -->
|
23
|
+
<!--a padding to disable MSIE and Chrome friendly error page -->
|
24
|
+
|
11
25
|
textStatus:error
|
26
|
+
|
12
27
|
errorThrown:OK
|
13
28
|
###ソースコード
|
14
29
|
```HTML
|
@@ -64,7 +79,7 @@
|
|
64
79
|
|
65
80
|
$.ajax({
|
66
81
|
type:"post",
|
67
|
-
url:"
|
82
|
+
url:"/php/sample/send.php",
|
68
83
|
data:JSON.stringify(data),
|
69
84
|
crossDomain: true,
|
70
85
|
dataType:"json",
|
@@ -116,19 +131,16 @@
|
|
116
131
|
```PHP
|
117
132
|
<?php
|
118
133
|
|
119
|
-
$request = isset($_SERVER['HTTP_X_REQUESTED_WHIT']) ? strtolower($_SERVER['HTTP_X_REQUESTED_WHIT']): '';
|
120
|
-
|
134
|
+
<?php
|
121
135
|
|
122
|
-
|
136
|
+
header("Content-type: application/json; charset=utf-8");
|
123
|
-
|
137
|
+
if(isset($_POST['request'])){
|
138
|
+
echo "OK";
|
139
|
+
}
|
140
|
+
else{
|
141
|
+
echo 'The parameter of "request" is not found.';
|
142
|
+
}
|
124
143
|
|
125
|
-
$text = isset($data['text']) ? $data['text']: "";
|
126
|
-
$callback = isset($_GET['callback']) ? $_GET['callback']: "";
|
127
|
-
$callback = htmlspecialchars(script_tags($callback));
|
128
|
-
|
129
|
-
header('Content-type: text/javascript; charset=utf-8');
|
130
|
-
printf("{$callback(%s)}", json_encode($data));
|
131
|
-
|
132
144
|
?>
|
133
145
|
```
|
134
146
|
|
1
errorメッセージを変更しました!
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,8 @@
|
|
6
6
|
当方、PHP、Ajaxをほとんど触ったことがないためわかりやすい解説をお願いします。
|
7
7
|
|
8
8
|
###発生している問題・エラーメッセージ
|
9
|
-
XMLHttpRequest:
|
9
|
+
XMLHttpRequest.status:404
|
10
|
+
XMLHttpRequest.responseText:undefined
|
10
11
|
textStatus:error
|
11
12
|
errorThrown:OK
|
12
13
|
###ソースコード
|
@@ -72,7 +73,8 @@
|
|
72
73
|
alert(data.text)
|
73
74
|
},
|
74
75
|
error: function(XMLHttpRequest, textStatus, errorThrown){
|
75
|
-
alert("XMLHttpRequest:"+XMLHttpRequest);
|
76
|
+
alert("XMLHttpRequest.status:"+XMLHttpRequest.status);
|
77
|
+
alert("XMLHttpRequest.responseText:"+XMLHttpRequest.responseText);
|
76
78
|
alert("textStatus:"+textStatus);
|
77
79
|
alert("errorThrown:"+errorThrown);
|
78
80
|
}
|