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

質問編集履歴

1

誤字

2021/01/05 10:25

投稿

lemonediscream
lemonediscream

スコア27

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,17 @@
1
+ jsの★の部分のnの値を一番下のコードのstandard.blade.phpで値を受け取りたいです。
2
+ jsで以下のコードでstandard.blade.phpに値をセットをしております。
3
+ **$('#getresult').val(n);**
4
+ standard.blade.phpで
5
+ **<input type="hidden" name="getresult" id="getresult" value=""/>**
6
+ のvalueで値をセットできていると思って、
7
+ **<?php
8
+ if(isset($_POST[‘getresult’])){
9
+ $comment = $_POST[‘getresult’];
10
+ echo $comment;
11
+ }
12
+ ?>**
13
+ 上記のコードで確認しようと思ったのですが、**Use of undefined constant ‘getresult’ - assumed '‘getresult’'** のエラーがでます。
14
+ 改善方法をお願い致します。
1
15
  ```js
2
16
  $(document).ready(function () {
3
17
  //検索ボタンをクリックした処理
@@ -9,11 +23,7 @@
9
23
  //送信データの準備
10
24
  var postData = {
11
25
  'sceneId': _scenarioSelected,
12
- 'elements': _elements,
26
+ 'elements': _elements
13
- 'elementNames': _elementsName,
14
- 'headers':, _headers,
15
- 'catId': _catSelected,
16
- 'condAndOr': _condAndOrVal
17
27
  };
18
28
 
19
29
  //データの取得(検索処理)
@@ -35,7 +45,9 @@
35
45
 
36
46
  //★ここのnの値をphp側に渡したいです
37
47
  var n = result.aaData;
48
+ //standard.blade.phpに値をセット
38
49
  $('#getresult').val(n);
50
+       //値を確認できています
39
51
  console.log(n[0]);
40
52
 
41
53
  }).fail(function (data, textStatus, xhr) {
@@ -43,4 +55,54 @@
43
55
  });
44
56
  });
45
57
 
58
+ ```
59
+ ```php
60
+ class ScenarioAjaxController extends Controller
61
+ {
62
+ public function getSearchResult(Request $request)
63
+ {
64
+ if (!$request->ajax()) {
65
+ return response()->json([],401);
66
+ }
67
+
68
+ $data = $this->getSearchData($request);
69
+
70
+ $response = array(
71
+ "aaData" => $data
72
+ );
73
+
74
+ echo json_encode($response);
75
+ }
76
+
77
+ }
78
+ ```
79
+ ```php
80
+ Route::post('ajax/searchResult', 'Ajax\scenarioAjaxController@getSearchResult');
81
+ ```
82
+ ```php
83
+ //standard.blade.php
84
+ <!doctype html>
85
+ <html lang="jp" class="no-js">
86
+
87
+ <head>
88
+
89
+ @include('css_js_part',['activePage'=>'standard'])
90
+
91
+ </head>
92
+ <body>
93
+ <div class= "getResult">
94
+ <form name="getresult" id="getresult" method="post">
95
+ @csrf
96
+ <input type="hidden" name="getresult" id="getresult" value=""/>
97
+ </form>
98
+ </div>
99
+ </body>
100
+
101
+ </html>
102
+ //<?php
103
+ //if(isset($_POST[‘getresult’])){
104
+ // $comment = $_POST[‘getresult’];
105
+ //echo $comment;
106
+ //}
107
+ ?>
46
108
  ```