teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記

2016/11/17 17:17

投稿

退会済みユーザー
answer CHANGED
@@ -30,3 +30,49 @@
30
30
 
31
31
  window.open のようにURLをオープンする機能なのですから、openが実行された時、特に何も設定していない限り、GETでのアクセスになるはず。だから、ここでエラーになっているはずという見立て。
32
32
 
33
+ ---
34
+
35
+ index.php
36
+
37
+ ```html
38
+ <!DOCTYPE HTML>
39
+ <html lang="ja">
40
+ <head>
41
+ <meta charset="UTF-8">
42
+ <title></title>
43
+ </head>
44
+ <body>
45
+ <script type="text/javascript" src="//code.jquery.com/jquery-3.1.1.min.js"></script>
46
+ <script type="text/javascript">
47
+ $(function () {
48
+ $.ajax({
49
+ type: "POST",
50
+ url: './testajax.php',
51
+ cache: false,
52
+ data: {
53
+ 'test': 2
54
+ },
55
+ success: function (data) {
56
+ console.log(data);
57
+ }
58
+ });
59
+ });
60
+ </script>
61
+ </body>
62
+ </html>
63
+ ```
64
+
65
+ testajax.php
66
+
67
+ ```php
68
+ <?php
69
+
70
+ $test = filter_input(INPUT_POST, 'test');
71
+ echo $test;
72
+ ```
73
+
74
+ 上記ソースコードの実行結果 こちらの環境では 2 となります。
75
+
76
+ ![イメージ説明](f261a85ddc0e5fc768f64c6f31ff46e8.png)
77
+
78
+

1

追記

2016/11/17 17:17

投稿

退会済みユーザー
answer CHANGED
@@ -4,4 +4,29 @@
4
4
  var ref = cordova.InAppBrowser.open('http://192.157.13.5/testajax.php');
5
5
  ```
6
6
 
7
- この行で出ているのでは?
7
+ この行で出ているのでは?
8
+
9
+ ---
10
+
11
+ ```
12
+ Notice: Undefined index:test
13
+ ```
14
+
15
+ このエラーを返すのは、
16
+
17
+ ```php
18
+ $data = $_POST['test'];
19
+ ```
20
+
21
+ の行です。
22
+ なので、$.ajax でアクセスされていることは間違いない。
23
+
24
+ Notice: Undefined index:test
25
+
26
+ は、POSTでアクセスしていないか、POSTでアクセスされていても、$_POST['test'] が渡されていないかどちらかです。
27
+
28
+ InAppBrowser プラグイン
29
+ [http://s.docs.monaca.io/ja/reference/cordova_5.2/inappbrowser/]( http://s.docs.monaca.io/ja/reference/cordova_5.2/inappbrowser/)
30
+
31
+ window.open のようにURLをオープンする機能なのですから、openが実行された時、特に何も設定していない限り、GETでのアクセスになるはず。だから、ここでエラーになっているはずという見立て。
32
+